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开发者_JS百科 length? Thanks Nayn
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.
20.1. Automatic schema generation
DDL can be generated from your mapping files by a Hibernate utility. The generated schema includes referential integrity constraints, primary and foreign keys, for entity and collection tables. Tables and sequences are also created for mapped identifier generators.
You must specify a SQL Dialect via the hibernate.dialect property when using this tool, as DDL is highly vendor-specific.
First, you must customize your mapping files to improve the generated schema. The next section covers schema customization.
20.1.1. Customizing the schema
Many Hibernate mapping elements define optional attributes named length, precision and scale. You can set the length, precision and scale of a column with this attribute.
<property name="zip" length="5"/>
<property name="balance" precision="12" scale="2"/>
from:http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/toolsetguide.html
精彩评论