-->
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.  [ 7 posts ] 
Author Message
 Post subject: Cascade not working
PostPosted: Tue Feb 17, 2004 5:57 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
Hi, can somebody tell me why cascade is not working here?

<class name="Boss" table="Boss">
....
<set name="guards" inverse="true" cascade="all">
<key column="boss_id"/>
<one-to-many class="Guard"/>
</set>
....
</class>

<class name="Guard" table="Guard">
....
<many-to-one name="boss" column="boss_id"/>
....
</class>

And this is the code:
Transaction tx = sess.beginTransaction();
Boss b = (Boss)sess.load(Boss.class, new Long(29));
Guard g = new Guard();
g.setName("Miei");
g.setBoss(b);
b.addGuard(g); //addGuard only add the object to Set of Guard
tx.commit(); //error on this line

I was thinking that I don't have to save "g" first because I use cascade, but seem that it didn't work.

And I get this error:
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 6:05 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
I may be wrong, but I'm not sure it makes much sense to have cascade enabled on inverse collections...

Basically, inverse means the owning entity doesn't manage the collection.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 6:22 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
brenuart wrote:
I may be wrong, but I'm not sure it makes much sense to have cascade enabled on inverse collections...

Basically, inverse means the owning entity doesn't manage the collection.


I don't know much about that.
Actually I was just following the example from Hibernate 2.1.1 Documentation, Chapter 9. Parent/Child Relationships, about cascade.
There I see that it set inverse=true and cascade=all

I've also tried to remove the "inverse" attribute, but it still didn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 6:39 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Turn Hibernate debug on and post it - may be easier to track the pbl.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 6:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
brenuart wrote:
I may be wrong, but I'm not sure it makes much sense to have cascade enabled on inverse collections...

It makes sence.
inverse="true" is only about relationship management

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 6:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check you unsaved-value

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 7:00 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
Thanks!
It turns out that I wrote unsaved-value=null but I use primitive type for the identifier.
I changed it to use primitive wrapper object and it worked.


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