I appreciate your ideas about how to recover from a StaleStateException - but it still leaves the open question: once you receive a StaleStateException, should you even *try* to recover? I've heard that once you get ANY exception, that you should rollback any outstanding transactions and close the session. I don't know if this is true or not. I wish I could find a definitive answer.
I like your idea about refresh. However, I'd still like to find out if evict() couldn't be used to remove this "stale" object from my cache. Also, another idea - instead of doing a refresh (which WOULD go to the database), perhaps I could "store" the original state of the object before I change it - then, if I get a StaleStateException, I could "restore" the original saved state. Perhaps if I did this, the session would be smart enough to realize that I had NOT actually changed the object - and, therefore, wouldn't try to write any changes from the DB... Don't know if hibernate is this smart or not...
Anyone out there have an answer?
Any light you can shed would be very appreciated.
-john
|