An update...
I am currently leveraging an EntityListener to disable dirty checking...
Code:
public class ReadOnlyEntityListener {
@PostLoad
public void postLoad(Object entity) {
Session session = HibernateUtil.getSession();
if (session != null) {
session.setReadOnly(entity, true);
}
}
}
This has a shortcoming in that a snapshot of the entity is constructed before postLoad runs.
With that said, I really want to declare the class immutable and use setReadOnly(entity, false) to re-enable dirty checking in the event that the entity does need to be changed. But, from what I've read in http://docs.jboss.org/hibernate/core/3.5/reference/en/html/readonly.html, it appears that I cannot do that...
Quote:
Hibernate treats a persistent entity of an immutable class the same way as a read-only persistent entity of a mutable class. The only exception is that Hibernate will not allow an entity of an immutable class to be changed so it is not read-only.
Please advise... Tom