Java/Hibernate + HSQLDB java.sql.BatchUpdateException: data exception: string data, right truncation

StackOverflow https://stackoverflow.com/questions/21410585

  •  03-10-2022
  •  | 
  •  

Question

I am testing an application locally using a memory-based HSQLDB. So far everything went fine, however, when executing a testcase with a String bigger than 256 chars I ran into an error.

Caused by: java.sql.BatchUpdateException: data exception: string data, right truncation;  table: TABLENAME column: COLNAME
at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 30 more

I gathered that the cause of this error is usually an "overflow" of the datatype one is using.

What bothers me is that I explicitly defined the column to be 4000 chars big, using the hbm.xml files.

<property name="translation" type="java.lang.String" length="4000">
     <column name="COLNAME" not-null="false" />
  </property> 

When I cut the test string down to 256 chars or less everything starts working again. 257+ chars and the error is thrown. I don't really see the reason why this is happening. Why would HSQLDB define this column as length="256", when I explicitly state that it's supposed to be 4000...

Can anyone help?

Best regards, daZza

Was it helpful?

Solution

Well, for whatever reason HSQLDB seems to do a bad mapping for certain types and values specified in the config file to the real tables it creates.

I was able to fix the issue by changing the "type" attribute to type=text. Now everything works perfectly. I just hope that after I finish testing the application it still works with the original MSSQL DB and maps text to a varchar then...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top