• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about design

 
Laura Barroso
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Laura,

do ManyToMany relationships not require join tables ? Is there such a join table for the ManyToOne relationship in your datamodel ?
 
Laura Barroso
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't have a join table...I just have this relationship(ManyToOne)
 
Emmanuel Garcia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use Interceptor API , there is a onDelete event you can override to do whatever you like.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic