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: on-delete="cascade" with one-to-one association
PostPosted: Wed Jun 01, 2005 5:57 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hibernate version:3.0.3

Mapping documents:

parent:
...
<one-to-one name="child" class="Child" property-ref="parent"/>
...

child:
...
<many-to-one name="parent" class="Parent" column="PARENT_ID" unique="true"/>
...


I'm mapping objects exactly like it suggested in the reference. But I can't figure out how can I define on-delete="cascade" to trigger DB level deletion of the child object.

Is it possible while DON'T want to use set, list etc ...

Thanks a lot!
Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 6:26 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Misha

Can you make it clear?

You have stated as one-to-one assocation in the subject line.

And in your mapping file you have stated it as

<one-to-one name="child" class="Child" property-ref="parent"/>

<many-to-one name="parent" class="Parent" column="PARENT_ID" unique="true"/>

This is wrong way of mapping.

Let me exact Association?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 7:38 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hi,

Sorry for being unclear :)

The two lines are taken from different mapping files. First one from parent's and second from child's. This is one-to-one bidirectional association.

Look at the hibernate reference - pages 61 bottom - 62 top.

Does anyone have a clue?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 7:50 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi Misha

Check this out, No Set, bag for one-to-one association


Mapping for Parent
<one-to-one name="child" class="Child" cascade="all"></one-to-one>


Mapping for Child
<id name="childId" type="int" column="childId">
<generator class="foreign">
<param name="property">parent</param>
</generator>
</id>
<one-to-one name="parent" class="Parent" constrained="true" cascade="save-update"></one-to-one>


Try this and Let me know the results

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 8:10 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hi Ramnath,

Thanks a lot for help! But your solution is not what i'm looking for.

In your example (as well as in mine) in case of deletion of the parent object, hibernate will perform the cascading logic and delete the child.

But I don't want it to do it. Instead, I want to use on-delete="cascade" option which will add "on delete cascade" flag to the foreign key in the Database.

The problem is, that this option (on-delete="cascade") could be used only with <key> element, which is part of <set>,<list> ...

Hibernate team?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 01, 2005 2:29 pm 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Anyone?

I'm sure that there is a way to do it ...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 1:33 pm 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Hibernate team?????????

Can you please respond to this topic ... i need to know if there is something that i'm missing here, or this is unsupported functionality??


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
on-delete="cascade" is not supported for a <one-to-one>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 3:59 am 
Beginner
Beginner

Joined: Tue Jan 04, 2005 5:39 am
Posts: 37
Thanks :)

Why is that? Is it some conceptual consideration, or just a missing feature?

Thanks again for the response!

Michael.


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.