Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist
hibernate java exception    2017-07-19 22:13:27    1114   
lightingfire   hibernate java exception

Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist  

今天 用JPA保存数据的时候出现此错误。

 

原因:   ID生成策略  我设置的自动。但是代码里面还是手动给对象ID设置了值

 

解决方案: 去掉手动给ID设置值的代码即可。


如:

 @Id

 @GeneratedValue(strategy = GenerationType.IDENTITY)

 @Column(name = "id", unique = true, nullable = false)


这种情况下,会报错,因为对id仅仅是设置了主键,并没有设置自增长,将

    @GeneratedValue(strategy = GenerationType.IDENTITY)

去掉即可

 

 


 

by 刘迎光@萤火虫工作室 
OpenBI交流群:495266201 
MicroService 微服务交流群:217722918 
mail: liuyg#liuyingguang.cn 
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

Pre: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test)

Next: avaya CM查看VDN指向的技能组


Table of content