user217631
user217631

Reputation: 1308

save to mysql database when some field exceeds field length

I'm using hibernate over mysql to save data where some fields can exceed the length limit:

Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'telephone' at row 1

I can not change the field length, the field is varchar(45). Is there a simple way to persist the record anyway into the database? I don't care if the field saved is truncated or nothing at all.

Upvotes: 0

Views: 242

Answers (1)

Firo
Firo

Reputation: 30813

i would just truncate in the setter of the string field, then the object behaves the same wether it is created or saved and loaded from database.

Upvotes: 1

Related Questions