*
The moose likes Object Relational Mapping and the fly likes Question about design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Question about design " Watch "Question about design " New topic
Author

Question about design

Laura Barroso
Ranch Hand

Joined: Sep 21, 2009
Posts: 30
I know that an unidirectional ManyToOne doesn’t support deletion in cascade so my solution was to put it bidirectional…of course, this bring the issue that you probably don’t need it in the other end of the relationship…but I think that I could place the getter and setter methods that hold my relation private and fetch my collection lazy…there! Problem solves!

However when I consult my boss he says that this was not a good approach to solve this problem, that my solution make the classes dirty!, that he rather to make this deletion thing with a query and then delete the other entity (the entity who should have the OneToMany side).

So my question is: is this true? My solution isn’t a good approach???


Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Laura,

do ManyToMany relationships not require join tables ? Is there such a join table for the ManyToOne relationship in your datamodel ?


SCJP 5 (98%) - SCBCD 5 (98%)
Laura Barroso
Ranch Hand

Joined: Sep 21, 2009
Posts: 30
No, I don't have a join table...I just have this relationship(ManyToOne)
Emmanuel Garcia
Greenhorn

Joined: Feb 24, 2009
Posts: 12
Hi Laura:

I believe the your boss is correct, but before two things:

1- A relationship OneToMany is the same thing that ManyToOne.
2- A relationship is bidirectional or not if you put in the code the correct method to return anohter bean and the <crm-field> in the descriptor,
in the relationship role in the descriptor you should write the source and destiny beans,
always

What is my opinion ? put <cascade-delete /> in the bean with multiplicity One
Laura Barroso
Ranch Hand

Joined: Sep 21, 2009
Posts: 30
That's what I think too: I mean, I could fix the problem with multiplicity OneToMany, but...they said to me that this approach make my class dirty because every time that I have to bring the entity that holds the OneToMany relationship then it will load the entire collection, but I think that if I put fetch = fecth.LAZY I won't need to worry about that collection….
Emmanuel Garcia
Greenhorn

Joined: Feb 24, 2009
Posts: 12
Hi Laura:

I have a doubt.

What was the first problem ?

because you have spoken about multiplicity, cascade delete, relationships.

Regards.
Laura Barroso
Ranch Hand

Joined: Sep 21, 2009
Posts: 30
The problem is about if it is a good approach to put a class with a OneToMany relationship, even if it doesn't need to know about the collection that it holds in order to let the container handle everything with cascade...
Justin Chi
Greenhorn

Joined: Sep 09, 2009
Posts: 25
I think you can use Interceptor API , there is a onDelete event you can override to do whatever you like.
 
 
subject: Question about design
 
Similar Threads
EJB 3.0 Entities and Webservices
Double-checked locking and the Singleton pattern ?
Is it a right approach ?
Interview Experiences
Hibernate 2: how to write a query when the result is not in some list