detached entity passes to persist error in hibernate/jpa with same example on this link.
public static void main(String[] args){
UserBean user = new UserBean();
user.setId(1);
user.setUserName("name1");
user.setPassword("passwd1");
em.persist(user);
}
caused due to: setting id explicitly
The question is why has this entity become detached ? From my understanding when you create a new entity it is transient and when you try to persist it ,it becomes persistent. So how can the entity become detached since detached entity is it not currently in the persistent context but in the database?
Help and Correct me if I am wrong somewhere.