Reputation: 335
I must be missing something obvious; however I am struggling to find an answer to a problem I am having with Hibernate Envers.
Let's say that I have entity class called MyObject that is audited using envers.
If I get the current copy of an instance of MyObject doing something like:
Session session = sessionFactory.getCurrentSession();
MyObject myobject1 = (MyObject) session.get(MyObject.class, 1234);
And I get an historical copy (from revision 2) of the same instance:
Session session = sessionFactory.getCurrentSession();
AuditReader reader = AuditReaderFactory.get(session);
MyObject myobject2 = reader.find(MyObject.class, 1234, 2);
Is there any way of distinguishing myobject1 from myobject2? How would I know that myobject1 was the current copy and myobject2 was from revsion 2?
Upvotes: 1
Views: 2717
Reputation: 8606
There's no "official" way. Both are just objects instantiated with different data.
You could, although, check if the session
contains myobject1
/myobject2
(using the contians
method: http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/Session.html). This will work as long as you don't clear or change the persistence context, and will return true
for "current" entities and false
for the historical ones. But that's more of a work-around than a proper solution.
Upvotes: 1