I don't know if calling evict is a requirement for you or not, but what you could do is set this in Hibernate configuration (*.cfg.xml):
<property name="hibernate.connection.autocommit">false</property>
This means your object would not get updated until you explicitely called session.save or something like that. In this case you wouldn't need to call evict - you could just modify the object, and if your user wasn't happy with changes, then simply abandon changes. On the flipside, you'd need to always call session.something to persist your changes.
If you're running in transacted environment, you might also look at those config parameters:
hibernate.transaction.flush_before_completion
hibernate.transaction.auto_close_session
HTH,
Bratek
|