[英]How to convert varchar to java.sql.Clob
Previously I had a data base column
name called summary and it's type was varchar
以前我有一个名为summary的数据库
column
名称,其类型为varchar
private String summary;
In recently i wanted to change this column data type into TEXT
to enable store large data.To do that i have used lob
annotation in hibernate
. 最近我想将此列数据类型更改为
TEXT
以启用存储大数据。为此,我在hibernate
使用了lob
注释。
@lob
private String summary;
As a result of that i can store large amount of data to that summary field.But the problem is that i have some old records that summary field contains varchar. 因此,我可以将大量数据存储到该摘要字段中。但是问题是我有一些旧记录,其中摘要字段包含varchar。 When get the data set it throws an error saying
An attempt was made to get a data value of type 'java.sql.Clob' from a data value of type 'VARCHAR'
.So my questions are, 当获取数据集时,它抛出一个错误
An attempt was made to get a data value of type 'java.sql.Clob' from a data value of type 'VARCHAR'
。我的问题是,
Please if anyone knows drop your answer. 如果有人知道,请不要回答。
The easiet way to migrate from string to clob: 从字符串迁移到Clob的最简单方法是:
1- add an intermediate attribute like this 1-添加这样的中间属性
@lob private String summaryAux;
and delete @lob from the summary attribute 并从summary属性中删除@lob
2- use a java main function that get all the records and set the "summary" into the "summaryAux". 2-使用Java主函数获取所有记录,并将“摘要”设置为“ summaryAux”。
main(){
List<Record> records = getAllRecors();
for(Record record: records){
record.setSummaryAux(record.getSummary());}
saveRecords(records);
}
3-delete the 3-删除
@lob private String summaryAux;
from your code and put @lob again on private String summary;
从您的代码中,然后将@lob再次放在
private String summary;
and also delete summary column from the the associated table and finally rename summaryAux column => summary 并从关联表中删除摘要列,最后重命名summaryAux column => summary
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.