Hi there, I've got these three entities in a sample project based on an ipotetic bus time table, in order to make some practice with hibernate and persistence in general.
Two of these entities are related to one called ServiceStop, which basically is a single stop for every bus service.
I'm havig some troubles with the remove action (I haven't tried the update yet), I can successfully remove the service and the serviceStop related, but the stop entity keeps the relation. What's the best approach to remove the relation only and keep the stop entity?
It is all based on the setting of the cascade relationship. Now Hibernate has a cascade option called delete-orphan that JPA does not have. You can try setting the relationship cascade to add the hibernate cascade option of delete-orphan.
So how are you calling remove, what object are you passing in to the method, or is it that you are removing the child objects from the list?
OK, I think I am starting to see what you are trying to get at.
You don't want any records deleted, you just want the FK to be nulled out right?
So when it comes to mapping relationships, it is important sometimes to make it bi-directional, as in your object code you are doing. So if you have a mapping in one direction and a mapping in the other direction, ORM does not know that this maps to the same relationship. You need to have one side declared as the inverse.
So on one side, you will included a "mappedBy=" annotation attribute. And point to the other classes instance var that has the same relationship mapping.
You probably can remove the delete-orphan because that definitely deletes the record if you remove it from the list.