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.
Mark
Alessandro Ilardo
Ranch Hand
Joined: Dec 23, 2005
Posts: 218
posted
0
It works.
Before use the element mappedBy it had (now disappeared) a join table with StopID and ServiceStopID. Did it use that beacause it didn't know what was the owner??
Thank you very much for your support. [ August 17, 2007: Message edited by: Alessandro Ilardo ]