-->
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.  [ 4 posts ] 
Author Message
 Post subject: TransientObjectException many-to-one
PostPosted: Wed Mar 09, 2005 12:58 pm 
Newbie

Joined: Wed Mar 09, 2005 12:54 pm
Posts: 5
I am struggling with a strange problem. I have two classes, typical many-to-one unidirectional association. Load a child in one session, send the child object together with the parent (no lazy load) to remote clients via RMI. Modify the child on client side and send the child back to server and saveOrUpdate() the child in a new session. I get net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:, complaining that the parent object, which just travels with the child to the client side and back without being modified, is transient.
Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 1:48 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Without any code/mappings it may be difficult...
I assume that you are cascading from child to parent. Is this desired?
What are your unsaved values set to for your identifier?


Top
 Profile  
 
 Post subject: TransientObjectException many-to-one
PostPosted: Mon Mar 14, 2005 12:39 pm 
Newbie

Joined: Wed Mar 09, 2005 12:54 pm
Posts: 5
It is a quite essential 1:n relationship. A partner has n contracts. I just have an unidirectional relationship from contract to partner.


<hibernate-mapping package="com.hdb.model">

<class name="Contract" table="Contract">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">CONTRACT_S</param>
</generator>

</id>

<timestamp name="updateTimestamp" column="UPDATE_TIMESTAMP"></timestamp>
<property name="type" column="TYPE" type="java.lang.Byte" />
......

<many-to-one name="partner" column="PA_ID" class="Partner" cascade="none" />
</class>

</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="com.hdb.model">

<class name="Partner" table="Partner">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">PArtner_S</param>
</generator>
</id>
<timestamp name="updateTimestamp" column="UPDATE_TIMESTAMP"></timestamp>
<property name="name" column="NAME" type="java.lang.String" not-null="true" />
......
</class>

</hibernate-mapping>


I didn't specified any unsaved-value, which should be null in the default case. I had similar mapping done without problem. But this time, I always run into this TransientObjectException. The programm looks like:
open a session, load a contract and return it, close session. Use the reference returned (which is detached now), change an attribute, open a session, update it, commit, close session. (Everything is fine until now). Use the same reference, change another attribute, open a session, update it, commit and close session. bang, an exception is thrown, complaining that the related partner object is transient.

The situation doesn't change, when I put unsaved-value="null" for the partner object.

Any clue?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 12:47 pm 
Newbie

Joined: Wed Mar 09, 2005 12:54 pm
Posts: 5
I made a small error in my previous problem description. The exception is thrown upone the first update invocation of the detached object.


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