-->
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.  [ 3 posts ] 
Author Message
 Post subject: Please ...Please help me to resolve this.
PostPosted: Wed Jul 30, 2008 2:11 pm 
Newbie

Joined: Wed Jul 30, 2008 11:28 am
Posts: 2
The following exception is coming, when I am trying to execute below client code.(Example).


org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.sandp.care.model.AnnouncementSummaryModel




Client Code..
______________________________________________
AnnouncementModel announcementModel = new AnnouncementModel();
announcementModel.setId(1l);
IndexModel indexModel = new IndexModel();
indexModel.setId(1717l);

announcementSummaryModel.setAnnouncementModel(announcementModel);
announcementSummaryModel.setIndexModel(indexModel);
announcementSummaryModel.setEventsList(list);
announcementSummaryModel.setFlagFwdAnnct("0");

session.saveOrUpdate(announcementSummaryModel);

AnnouncementSummaryModel.hbm.xml(Parent mapping file)
________________________________________________________
<hibernate-mapping>
<class name="com.sandp.care.model.AnnouncementSummaryModel" table="CR_T_ANNOUNCEMENT_SUMMARY">
<id name="id" type="java.lang.Long">
<column name="ANNOUNCEMENT_SEQ_ID" precision="22" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="announcementModel" class="com.sandp.care.model.AnnouncementModel" fetch="select" lazy="false">
<column name="ANNOUNCEMENT_ID" precision="22" scale="0" />
</many-to-one>
<many-to-one name="indexModel" class="com.sandp.care.model.IndexModel" fetch="select" lazy="false">
<column name="INDEX_ID" precision="22" scale="0" />
</many-to-one>
<bag name="eventsList" table="CR_T_EVENT_DETAILS" lazy="false" inverse="true" cascade="all">
<key column="ANNOUNCEMENT_SEQ_ID"/>
<one-to-many class="com.sandp.care.model.EventDetailsModel"/>
</bag>
</class>
</hibernate-mapping>

EventDetailsModel:(Mapping file 2):
_________________________________________________________

<hibernate-mapping>
<class name="com.sandp.care.model.EventDetailsModel" table="CR_T_EVENT_DETAILS">
<id name="id" type="java.lang.Long">
<column name="EVENT_DETAILS_ID" precision="22" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="eventModel" class="com.sandp.care.model.EventModel" fetch="select" lazy="false">
<column name="EVENT_ID" precision="22" scale="0" />
</many-to-one>
<many-to-one name="announcementSummaryModel" class="com.sandp.care.model.AnnouncementSummaryModel" not-null="true">
<column name="ANNOUNCEMENT_SEQ_ID" precision="22" scale="0" />
</many-to-one>
<property name="effDate" type="java.util.Date">
<column name="EFF_DATE" length="7" />
</property>
<property name="refNo" type="java.lang.Long">
<column name="REF_NO" precision="22" scale="0" />
</property>
</class>
</hibernate-mapping>


____________________________


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 1:08 am 
Newbie

Joined: Wed Jul 30, 2008 7:48 am
Posts: 10
Location: NOIDA
Either use session.save for both objects or specify a cascade="save-update,persist" in your mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 4:33 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed, you may find that you have to save both sides of the association. Allowing both entities to 'touch' the Hibernate Session should alleviate this problem.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.