Hi all ,
I am having this exception thrown in my face whenever I try to persist my object as such
public String saveUser()
{ if (user.getPassword().equals(verify) ) { List existing = em.createQuery(query)
.setParameter("username", user.getUserName())
.getResultList(); if (existing.size()==0) { System.out.println(":: ABOUT TO SAVE ::::"); user.setCreatedBy(credentials.getUsername()); user.setCreatedDate(new java.util.Date()); //em.merge(user); em.persist(user); return "users";
} else
{
facesContext.addMessage(null, new FacesMessage("username already exists"));
return null;
} }
else {
facesContext.addMessage(null, new FacesMessage("re-enter your password"));
verify=null;
return null;
}
}
javax.ejb.EJBTransactionRolledbackException: org.hibernate.PersistentObjectException: detached entity passed to persist:
However whenever I call em.merge(user); it ends up doing an update.
Pls can I get help to put this issue to rest?
Thank you have a wonderful day
|