-->
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: PropertyException during save() with cascade
PostPosted: Tue Jul 20, 2004 11:24 am 
Newbie

Joined: Tue Jul 20, 2004 11:02 am
Posts: 2
Hi:

I have a simple one-to-many relationship with cascade "all". The code to create objects is as follows:

hibSession = ConnectionMgr.openHibernateSession();
TheOne to = new TheOne();
to.setMyValue("One Value");
TheMany tm = new TheMany();
tm.setMyValue("Many Value");
HashSet set = new HashSet();
set.add(tm);
to.setTheManys(set);
hibSession.save(to);

I get the exception shown below indicating a problem with not-null property (see below exception for XML descriptors):

08:50:05,721 FATAL [ConnectionMgr] gsgjwynett.rsinc.com | Failed to flush Hibernate session
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.digitalglobe.nextview.ppq.dataobjects.TheMany.theOne
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1276)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2567)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2454)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2256)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2235)

<set name="theManys"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted">
<key column="the_one_id"></key>
<one-to-many
class="com.digitalglobe.nextview.ppq.dataobjects.TheMany"
/>
</set>

<many-to-one
name="theOne"
class="com.digitalglobe.nextview.ppq.dataobjects.TheOne"
cascade="all"
outer-join="true"
update="true"
insert="true"
access="property"
column="the_one_id"
not-null="true"
/>

_________________
Jon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 11:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
tm.setTheOne(to)


In future, please use your debugger before posting to the forum, TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 5:34 pm 
Newbie

Joined: Tue Jul 20, 2004 11:02 am
Posts: 2
I hate to bother you with this again but I've tried every possible option I can think of, poured through the debug logs, traced code and unless I'm missing something, I can't see a way to make this work. I'm sure I'm missing one small item that will make this work or else I misunderstand how cascade works.

The code I started with before your reply was:

TheOne to = new TheOne();
to.setMyValue("One Value");
TheMany tm = new TheMany();
tm.setMyValue("Many Value");
HashSet set = new HashSet();
set.add(tm);
to.setTheManys(set);
hibSession.save(to);

If I remove the

to.setTheManys(set);

and replace it with

tm.setTheOne(to);

It only saves TheOne and not TheMany since it when it gets to the cascade method, the child is null.

So my next thought is to try both these segments of code:

to.setTheManys(set);
tm.setTheOne(to);

Then it fails with this exception as Hibernate thinks it already saved TheMany with ID=0 and then tries to do an update. Of course the update fails because there is no row in the database:

ERROR [main] (SessionImpl.java:2375) - Could not synchronize database state with session net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)

The only thing I can get to work is shown below. However this seems to defeat the purpose of having a cascade:

TheOne to = new TheOne();
to.setMyValue("Locally the one.");
TheMany tm = new TheMany();
tm.setMyValue("Locally the many.");
tm.setTheOne(to);
s.save(to);
s.save(tm);

Thanks for your help.

_________________
Jon


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.