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???
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,
What is my opinion ? put <cascade-delete /> in the bean with multiplicity One
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….
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...