I have this problem. Let's have two entities, for example Car and Person. One person can own n cars, a car can be owned by one person, so it's one-to-many association. The association is unidirectional, you can obtain owner from
Code:
Person Car.getOwner()
, but you can't get list of cars from Person.
And now here's the problem. I need to remove Car and Person entities in this way:
1, when you remove a Car, his owner is not removed.
2, when you remove a Person, all his cars are removed.
I was able to solve the first point by simply removing CascadeType from the @ManyToOne annotation, so the removing of a Car doesn't remove the owner.
But I can't solve the second point, I can't add CascadeType.REMOVE to the Person class, because the association is unidirectional, so I dont use @OneToMany annotation there.
Thanks for your help!