I have a parent table for eg: User_Mst is my table and the corresponding POJO object is UserMst.java.
I also have a child table which is User_Addr_Mst and the corresponding POJO object is UserAddrMst.java.
The assocciation between the parent and child is one to many, so Set of UserAddrMst is aggregated with the parent POJO(UserMst).
Now iam fetching a record from User_Mst table using the session.query and iam gettinga the parent object which consist of child set(UserAddrMst).
My requirement is to create another user with the same details as the object with which i have. which means i want to insert a new record with the details of the current object.
How do i do this?
I tried cloning the parent object and tried setting the primary key as null, but it throws me an exception..
Code:
org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=HP16003273432/46, BranchQual=, localId=46] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.HibernateException: identifier of an instance of com.myproject.UserMst altered from 4444 to null)
I have the alternate solution as callling an store procedure.. but is it possible with hibernate.. is there any other method to replicate an object..??