So how do you get around this? I have an EJB application which is using Hibernate SessionFactory bound to EJB container's JTA. So session boundary is pretty much equivalent to transaction boundary. I also have a situation where I change filter parameters within single session, and like in the case described above, the query results are always the same (even when parameters are different) because Hibernate returns data from level 1 cache (the entity containing the collection is always the same).
Since I'm writing DAO layer that will be used by others to maintain persistence of their data, I don't think I can close/clear/reopen session just to flush collection data from the cache. What if they load other objects, update them, then call my method and I flush the session/cache? They will save their modified objects thinking they will be updated, but since Hibernate cache will not know about those objects (the session has been flushed), those objects will be inserted instead.
Is there a way to update the collection data without clearing the session? And if not, what can be done in this situation to get the expected results?
Bratek
|