-->
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: Many to 1 relation - TransientObjectException
PostPosted: Sat Feb 21, 2004 9:04 pm 
Beginner
Beginner

Joined: Sat Nov 22, 2003 3:54 pm
Posts: 42
Before putting out my problem these are the various imp things.

Using:
Hibernate 2.1
Database:DB2
Application - Web App -- Entities are loaded in 1 session and then saved in another session.

Now the problem Description------

EntityA has a relationship with EntityB, EntityC where EntityA will always be a child of EntityB and can also be a child of EntityC based on some business rule but not mandatory.

Entity A mapping document(relationship) looks like this---

<many-to-one name="EntityB" class="test.EntityB" not-null="true" >
<column name="codea" />
</many-to-one>

<many-to-one name="EntityC" class="test.EntityC" not-null="true" >
<column name="forcode" />
</many-to-one>
------------------------------------------------------
So for EntityA to exist "EntityB" must be present but not necessarily EntityC(only when required).

Now when i am trying to save "EntityA" (without an instance of EntityC which is not needed always) there comes this error
--------------------------------------------
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: test.EntityC
----------------------------------------------

Could you guide me where i am going wrong.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 4:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In the object graph you saved, EntityA instance refers to an EntityC instance which is not attach to the session.
Remove not-null="true" and don't setEntityC() in EntityA.

_________________
Emmanuel


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.