hibernate annotation 定义字段的默认值和显示hql的格式化问题
1 java类中定义属性的默认值并不能直接映射到数据库的定义当中 如 private String a="A"; public String getA(){}; 数据库的a字段并没有default. 用annotations column中的columnDefinition可以解决 @Column(columnDefinition="varchar2(2) default '11'") public String getA(){}; 字段就可以存在默认值了 注意字段的类型必须指定,因为hibernate会把columnDefinition的内容直接写在生成标的ddl中,因此语法必须正确。 2 hql自动生成的sql很大,而且输出后不容易调试。
在框架中core-config.xml中的hibernateProperties段加入设定参数可以改变。
<prop key="hibernate.use_sql_comments">true</prop>//sql加注释
<prop key="hibernate.format_sql">true</prop>//sql格式化
输出结果见附件
在头部加上: @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
俺也遇到这个问题
把字段先删掉再试试,如果字段存在,不会修改
@Column(columnDefinition="varchar2(2) default '11'") 我使用上面怎么沒有效果了,可能會是什麽原因呢??
http://www.iteye.com/topic/150309