hibernate 插入为空时保留数据库默认值

在插入数据时,如果数据库有默认值且插入值为null,则自动插入数据库默认值;如果插入值不为空则保留该值。看似简单一个需求,hibernate的实现都几经波折。
1.使用HBM文件时,加入
dynamic-insert= "true  dynamic-update= "true "


2.使用注解时,在类级别上添加
@org.hibernate.annotations.Entity(dynamicUpdate=true,dynamicInsert=true)

同时该 字段上的nullable=false

猜你喜欢

转载自chembo.iteye.com/blog/1734755
今日推荐