tags:

views:

31

answers:

1

Hi, I read that 'length' attribute in hibernate mapping file for a table column is optional. Does it truncate data while inserting into database if length exceeds the column length? Thanks Nayn

+1  A: 

The length attribute is used by the DDL generation tool to generate a script with the corresponding columns size. That's all.

So no, Hibernate does not truncate data, it will just try to write what you tell him to write and the insert or update statements will fail if data are longer than what can fit in a given column.

Pascal Thivent
Cool. I was looking for some way to not fail the insert in case data is longer than the limit but rather insert the trimmed content. Substring'ing the input in hibernate object's setter methods is one way. Please opine if that is fine.
Nayn
@Nayn: Trimming in the setter will work and is probably the best option.
Pascal Thivent