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.  [ 9 posts ] 
Author Message
 Post subject: Strange Exception
PostPosted: Sun May 13, 2007 7:17 pm 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
Hi,
The probelm Im facing is as under:

I have two tables A and B where B is parent table and the relation

between A and B is many-to-one.

Also the foreign key is nullable.
Now retrieving records is not a problem. But when I try to update the

retrieved row(of table A) where is the foreign key is null, it throws me

TransientObjectException:

ALso the cascading property has been set as "none". Why does it throw

that error even Im not trying to update the null foreign key . Im just

updating the value of some other column which doesnt have any

association.
Kindly Help:!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 11:29 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi sriguru,

I think it code problem. First know when TransientObjectException comes. It comes when any mapped class has object associated with any parent object. Where parent object is persistent and associated object is not persistent .At session.flush it would give you TransientObjectException .So Post your all mapping and class and also code within transaction scope.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Code:
PostPosted: Mon May 14, 2007 9:23 am 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
Hi,
The code for my program is:
mapping for A:
<hibernate-mapping package="parms">
<class name="A" table="A" lazy="true" batch-size="20" select-before-update='true' >
<id name="id" column="ID">
<generator class="increment"/>
</id>
<many-to-one name="b" column="Ba_ID" class="B" not-found="ignore"
cascade="lock" lazy="false" not-null="false" unique="false"/>
<property name="place" column="PLACE"/>

</class>

mapping for B:

<class name="B" table="B" lazy="true" batch-size="10" select-before-update="true">
<cache usage="read-write"/>
<id name="id" column="B_ID" >
<generator class="assigned"/>
</id>
<property name="programId" column="GROUP_ID" unique="true"/>
</class>

Now the only difference from a normal condition is that not all the rows in table A have non-null value for the column Ba_ID. That means some of rows have null values for column Ba_ID.
Now retrieval of these rows which have null values for column Ba_ID works fine. And it retrieves a null relationship between the tables for these rows. Now when I try to update column PLACE. It tries to update column Ba_ID also and there it throws me TransientOBjectException.
But I dont want to change anything for that column.


Top
 Profile  
 
 Post subject: Code:
PostPosted: Mon May 14, 2007 9:38 am 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
Hi,
The code for my program is:
mapping for A:
<hibernate-mapping package="parms">
<class name="A" table="A" lazy="true" batch-size="20" select-before-update='true' >
<id name="id" column="ID">
<generator class="increment"/>
</id>
<many-to-one name="b" column="Ba_ID" class="B" not-found="ignore"
cascade="none" lazy="false" not-null="false" unique="false"/>
<property name="place" column="PLACE"/>

</class>

mapping for B:

<class name="B" table="B" lazy="true" batch-size="10" select-before-update="true">
<cache usage="read-write"/>
<id name="id" column="B_ID" >
<generator class="assigned"/>
</id>
<property name="programId" column="GROUP_ID" unique="true"/>
</class>

Now the only difference from a normal condition is that not all the rows in table A have non-null value for the column Ba_ID. That means some of rows have null values for column Ba_ID.
Now retrieval of these rows which have null values for column Ba_ID works fine. And it retrieves a null relationship between the tables for these rows. Now when I try to update column PLACE. It tries to update column Ba_ID also and there it throws me TransientOBjectException.
But I dont want to change anything for that column.


Last edited by sriguru on Mon May 14, 2007 3:34 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Transaction scope code
PostPosted: Mon May 14, 2007 9:53 am 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
A a=_form.getA(id);
a.setPlace("place");
sess.saveOrUpdate(a);
tx.commit();
sess.close();

And the last SQL statement being tried to be executed is:
UPDATE A set ......(all columns )..... where ID =?


And the exception thrown is:

[ERROR] AbstractFlushingEventListener - -Could not synchronize database state with session <org.hibernate.TransientObjectException: B>
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 12:53 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi sriguru,

Replace hibernate3.jar with v3.2's hibernate3.jar that might help

Are you using replicated database server.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:08 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
read this

http://forum.springframework.org/archiv ... 37051.html

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:08 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
read this

http://forum.springframework.org/archiv ... 37051.html

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Hi Dharmendra
PostPosted: Tue May 15, 2007 10:33 am 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
I dont have replicated servers. And the problem I have is way different from the link you gave.
Its just a simple unidirectional many-to-one relationship, with the primary key of one table becoming foreign key of the second. The only new thing is that this foreign key column can also have null values.
And the problem occurs when I try to update a row of this child table without updating the foreign key. Also Im already using 3.2 hibernate.


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