"detached entity passed to persist error" with JPA/EJB code

Posted by zengr on Stack Overflow See other posts from Stack Overflow or by zengr
Published on 2010-03-14T08:25:17Z Indexed on 2010/03/14 8:35 UTC
Read the original article Hit count: 506

Filed under:
|
|

I am trying to run this basic JPA/EJB code:

public static void main(String[] args){
         UserBean user = new UserBean();
         user.setId(1);
         user.setUserName("name1");
         user.setPassword("passwd1");
         em.persist(user);
  }

I get this error:

javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.JPA.Database

Any ideas?

I search on the internet and the reason I found was:

This was caused by how you created the objects, i.e. If you set the ID property explicitly. Removing ID assignment fixed it.

But I didn't get it, what will I have to modify to get the code working?

© Stack Overflow or respective owner

Related posts about jpa

Related posts about ejb3