删除数据 DataIntegrityViolationException: notnull property references a null or transient value解决

今天在做删除某一个数据时
使用hibernate的getHiberbnateTemplate().delete(entity)时,报以下错误
javax.servlet.ServletException: org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: com.GameServer.Entity.News.NTitle; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: 

这是因为我在映射文件user.hbm.xml中使用not-null="true" 这使用delete()方法是系统会根据not-null来检查相应的值。而我的entity中只用id是不为null,其余是null。因此报错。


原文地址:https://www.cnblogs.com/zhihaowang/p/10128476.html