hibernate 中如何用注解映射定长字符类型char(2)

  如果是用xml的方式配置映射,可以在<column>标签的sql-type属性中设置char(2),比如:  

1 <property name="age" type="java.lang.String"> 
2   <column name="age" sql-type="char(2)"></column> 
3 </property> 

 

    如果是注解的话,需要使用@Column的columnDefinition属性,比如:

@Column(name="age",columnDefinition="char(2)")
private String age;

  column注解中的columnDefinition属性用于覆盖数据库DDL中的语句,比如:

@Column(name="age" columnDefinition = "char(2) DEFAULT not null COMMENT '年龄'") 

 

posted @ 2015-02-03 11:05  程序员一一涤生  阅读(1153)  评论(0编辑  收藏  举报