title: "detached entity passed to persist error" with JPA/EJB code
body: <p>I am trying to run this basic JPA/EJB code:</p>
  
  <pre><code>public static void main(String[] args){
           UserBean user = new UserBean();
           user.setId(1);
           user.setUserName("name1");
           user.setPassword("passwd1");
           em.persist(user);
    }
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.JPA.Database
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>I search on the internet and the reason I found was: </p>
  
  <blockquote>
    <p>This was caused by how you created the objects, i.e. If you set the ID property explicitly. Removing ID assignment fixed it.</p>
  </blockquote>
  
  <p>But I didn't get it, what will I have to modify to get the code working?</p>