A user is reporting my service is returning him error, reporting following exception:
Internal Exception: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'lastRegResult' at row 1
Error Code: 1406
The column in question is defined as VARCHAR(120)
, and it is quite possible the data I am attempting to store there are sometimes longer. I expected the data will be silently truncated, but it seems I was wrong.
I could shorten the data to 120 characters before calling setLastRegResult
, but I do not want to have a hardcoded constant 120 in my code, so that I do not have to update it if the database column size will change. How can I do this cleanly?
A solution might be:
- how can I read the size of the column so that I can truncate it myself?
- or, how I can tell the JPA to perform the truncation for me?