This question was partially covered by the "locking objects" thread earlier, but I thought I'd expand on it a bit.
What I'd like to be able to do, is to return a Hibernate-retrieved object from my facade, and for this object to be read-only to the facade client. By this, I mean that any changes which the client makes to the object will not be persisted to the database. Only when the object is passed back to the facade in a later method, will the changes be persisted (within a transaction controlled by the facade).
The simplest solution would be to detach the object from the session, allow the client to change it, then reattach to a new session, but unfortunately I need to be able to lazily fetch collections and the like, so that option's out.
Essentially, I need to "buffer up" all changes the client makes, so that I can be sure they won't be flushed until the DAO wants them to be. I could set the flush mode of the session to FlushMode.NEVER, but that won't stop a determined client from just flushing manually, and making the whole effort pointless.
I suspect that I'm on to a loser here, but I thought I'd throw this one out there and see if anything comes of it :)
|