-->
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.  [ 2 posts ] 
Author Message
 Post subject: [Mappingproblem] Two many-to-one mappings
PostPosted: Tue Mar 30, 2004 10:12 am 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
Hi there,

I am a bit lost. I don't know how to model this right.

Scenario:

* Objects A,B,C
* Object B is a child of A (so A.getBs() and B.getA(), one-to-many)
* Object B reference C (unidirectional assoziation).

Here comes the problem:
Since B reference C, the reference should be set to null if C gots deleted. (SQL: on delete set null).

But I was not able to get things right on first try. So I used a hack using an integer column (primary key of C) without a foreign key constraint. But now it's time to make things right.

So here are the options I can think of:

-Add a second bidirectional mapping between B and C (C is parent) and use onDelete methods on both side to remove the link before either B or C gets deleted (adds the burdon of utilizing the lifecycle, which I think is not such a good option).

-Life with the hack of integer and ensure that if any new C is generated using the same id, things gets corrected (logical link, but this smells that kind of badly that I would like to avoid this).

-Using an unidrectional mapping but again I ran into the problem, how I can create a behaviour like 'on delete set null'.

How is the 'best' way you know, this can be modeled using hibernate?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 12:34 pm 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
I implemented it using bidirectional mapping and also utilizes the lifecycle method onDelete() on B and C. So C removes all the Bs from its set if it gots deleted and B removes itself from C on its deletion. Works well but I am still suffering from being forced to introduce a feature (C knows about the Bs) without the need of it.

An other idea is to drop one side of the mapping and alter the onDelete method of C. So all what C has to perform is to find every B referencing the current C and dereference it. But again C has to be aware of B. But the set disappears. Is it that kind of smart? I had to introduce hibernate specific queries to the POJO. I would like to avoid it since I try to decouple the hibernate aspect as much as possible.

Any ideas on that?


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