Previously I had a data base column
name called summary and it's type was 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
.
@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. 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,
Please if anyone knows drop your answer.
The easiet way to migrate from string to clob:
1- add an intermediate attribute like this
@lob private String summaryAux;
and delete @lob from the summary attribute
2- use a java main function that get all the records and set the "summary" into the "summaryAux".
main(){
List<Record> records = getAllRecors();
for(Record record: records){
record.setSummaryAux(record.getSummary());}
saveRecords(records);
}
3-delete the
@lob private String summaryAux;
from your code and put @lob again on private String summary;
and also delete summary column from the the associated table and finally rename summaryAux column => summary
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.