错误:javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value …
这其实是idea使用hibernate的逆向工程生成hbm.xml配置文件的一个坑造成的问题
我数据库里只有id设的不允许为空,其他字段都允许为空,但是用idea的hibernate逆向工程生成hbm.xml是它却把所有字段都配置成了不允许为空
更改以后,下面的删除表记录的代码就能正常运行了。因为我传的productEntity对象到delete方法里,只为该对象设置了一个id属性,别的属性都为空,但配置文件里配置的是不允许别的属性为空。在这种冲突下就报了上面的错
ProductEntity productEntity=new ProductEntity();
productEntity.setId(1);
session.delete(productEntity);
transaction.commit();
session.close();
sessionFactory.close();