Hibernate 3.0.3
I have a web app upon which I'm using the Long Session pattern.
I load an object foo which has many associated, lazy connections.
Subsequently, the web framework I'm working with sets a number of fields in foo. Since foo is still associated with a session, Hibernate will write through these updates the next time the session flushes.
The problem is, this isn't what I want to happen; I need to do my own validations on the object before I determine if a save should really happen. I want hibernate to actually update the object if, and only if, I call Session.update(foo). Otherwise, I want to be able to manipulate foo to my hearts content without persisting the changes.
To an extent, I can accomplish this if I evict foo as soon as I load it e.g.
Session load(foo, id);
Session.evict(foo)
The problem with this approach though is that later on in the user's life he may, or may not, navigate to a screen which displays a lazy connection. If foo is evicted at that point, I get the infamous lazy initialization exception.
Can anyone suggest an approach whereby I can manipulate a persistent object without either A) having hibernate write through my changes automatically, or B) having to evict my object from the session?
|