null out all references to a removed entity
I have an entity Client and an entity Session. Client has a field currentSession
which references a Session entity. At some point, I end up deleting sessions, sometimes this is the client's current session. Is there any way that I can instruct my persistenc开发者_如何学Ce provider to null
the currentSession
field of a client if it references the session that I'm removing?
@Entity
public class ClientEntity {
@OneToOne
private SessionEntity currentSession;
}
When I'm done with a certain session; I want to remove it like this. Note that there is no guarantee that session
is also the client's current session.
entityManager.remove( session );
I could do it all in code, but that would just be ugly; and I'd like to have the persistence provider take care of this relationship management for me.
As far as I understand you are talking about what quite a lot of people miss in Hibernate, something like Cascade.SET_NULL. this has been discussed already here and there.
And as one of the posters advises, you'll need to do it by yourself in an interceptor or listener, or find another way around to achieve what you exactly need.
精彩评论