-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.TransientObjectException while saving clone
PostPosted: Mon Feb 14, 2011 12:13 pm 
Newbie

Joined: Wed Jan 19, 2011 6:30 am
Posts: 10
Hi All,

Code:
<class name="com.hibernate.list.TestMap" table="TEST_CLASS_TBL" lazy="false">
      <id name="strId" type="string" column="ID">
            <generator class="uuid.hex"/>
        </id>
<map name="mapCust" table="TEST_MAP_CUST" cascade="all" lazy="false">
         <key column="strId"/>
         <index-many-to-many class="com.hibernate.list.TestList" column="testList_id" />
         <many-to-many column="test_list" class="com.hibernate.list.TestList" />
      </map>
</class>



<class name="com.hibernate.list.TestList" table="TEST_LIST_TBL" lazy="false">
      <id name="strListId" type="string" column="listID">
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" column="name" />
   </class>



And while setting TestList object in map I want clone of same object
mapCust.put((TestList)objTestList.clone(), objTestList);


Also I have override clone method in TestList

Code:
public Object clone() {
      TestList objTestList = new TestList();
      
      if(name != null) {
         objTestList.setName(new String(name));
      }
      if(strListId != null) {
         objTestList.setStrListId(new String(strListId));
      }
      
      return objTestList;
   }



when I am trying to save this object it gives me exception

Code:
Hibernate: insert into TEST_CLASS_TBL (ID) values (?)
Hibernate: insert into TEST_LIST_TBL (name, listID) values (?, ?)
Hibernate: insert into TEST_MAP_CUST (strId, testList_id, test_list) values (?, ?, ?)
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.hibernate.list.TestList
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
   at org.hibernate.persister.collection.AbstractCollectionPersister.writeIndex(AbstractCollectionPersister.java:765)
   at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1141)
   at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:39)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at com.hibernate.list.CollectionExample.main(CollectionExample.java:72)
java.lang.NullPointerException
   at com.hibernate.list.CollectionExample.main(CollectionExample.java:171)
Hibernate: insert into TEST_MAP_CUST (strId, testList_id, test_list) values (?, ?, ?)
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.hibernate.list.TestList
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:78)
   at org.hibernate.persister.collection.AbstractCollectionPersister.writeIndex(AbstractCollectionPersister.java:765)
   at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1141)
   at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:39)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at com.hibernate.list.CollectionExample.main(CollectionExample.java:174)



But when I am trying to save same object without cloning it, then it's saving properly.

Please let me know where I am doing wrong?
Is there any problem with cloned object?

Thank You,
Navnath.


Top
 Profile  
 
 Post subject: Re: org.hibernate.TransientObjectException while saving clone
PostPosted: Tue Feb 15, 2011 9:58 am 
Newbie

Joined: Wed Jan 19, 2011 6:30 am
Posts: 10
Hi,

I got ans for this.
Actually problem was not with clone, it was with setting custom object as map key.
http://www.java2s.com/Code/Java/Hiberna ... bjects.htm

Thank you,
Navnath.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.