Evicting eager associations without cascade="evict"
Is there any way to make Hibernate evict both an entity and all of its eager or one-to-one as开发者_如何转开发sociations without having to evict associations manually one by one? (And without setting cascade="evict" on the association).
I usually find these kind of needs once the persistence layer is built and working, and I don't feel confident about adding this kind of configuration globally for those associations. I just want to cascade eviction in a particular case.
Also, it would be fine if there was a way to retrieve an entity from the DB without getting it (and its eager associations) attached to the session.
I want to do this to perform some comparison logic between an UI-modified entity and its current DB state. After the comparison logic, the UI-modified entity will always be saved. The logic behind the comparison doesn't have anything to do with the eager or one-to-one associations.
The answer to your first question is no.
I don't see why, in your second problem, you don't want to have the entity attached to the session. I can see why you don't want to load some associations, but that's precisely the goal of setting the associations as lazy instead of eager. Just don't make them eager, and they won't be loaded in the session.
What about writing a new function that does the comparison in DB directly and returns something?
That is suitable for your needs I think.
精彩评论