开发者

null out all references to a removed entity

开发者 https://www.devze.com 2023-04-11 17:55 出处:网络
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 ses

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消