detached entity passed to persist: com.test.usermanage.model.User

  1. 云栖社区>
  2. 博客>
  3. 正文

detached entity passed to persist: com.test.usermanage.model.User

一线分享 2015-05-25 11:12:58 浏览284
展开阅读全文

点击打开转载地址

Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.test.usermanage.model.User

at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
at com.test.usermanage.test.ClientEntity.main(ClientEntity.java:27)
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.test.usermanage.model.User
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:141)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:852)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)

... 1 more

User user = new User();
user.setId(2);
改:
User user = new User();
user.setId(null);


网友评论

登录后评论
0/500
评论
一线分享
+ 关注