I use Hibernate Envers with "withModifiedFlag = true" for table "user", the columns _mod is generated with boolean data. But I can not get list of changed columns by code, or the way to get them.
Asked
Active
Viewed 1,494 times
-2
-
You are missing a question. When you add it please also add: What you tried so far to solve the problem. How that did not work. What you experienced and what you expected instead. Also the results of your own conducted research regarding the problem. Thanks already. – Ben Jun 22 '18 at 10:58
-
Thank @Ben for your support. I create a object "user" and want to track changed history in database mySQL. I used Hibernate Envers (version 5.3.1), set annotation @Audited(withModifiedFlag = true) for "user" object and then table "user_aud" with columns
_mod is work fine ( boolean data). I have try to use AuditReader but I only get AuditQuery and data of the revision. I want get name of columns which is changed (value = 1) in table "user_aud". How to get changed column name of the revision in table "user_aud" ? – Toi Nguyen Jun 22 '18 at 11:18
1 Answers
3
This was a feature originally to be included in Envers 6.0 but we backported that as a part of Envers 5.3 as a part of HHH-8058. So as long as you are using at least Hibernate 5.3.0.Final or later you should have access to this feature.
A simple example below illustrates how to get all revisions for a given entity class by id.
List results = AuditReaderFactory.get( session ).createQuery()
.forRevisionsOfEntityWithChanges( YourEntityClass.class, false )
.add( AuditEntity.id().eq( entityId ) )
.getResultList();
This will return a list of object-array elements that consist of the following
- 0: The entity instance at that revision.
- 1: The revision entity instance, e.g.
DefaultRevisionEntity
or your custom revision entity. - 2: The revision type of the revision, e.g.
ADD
,MOD
, orDEL
. - 3: A
Set<String>
collection that contains all property names that were modified in that revision.
So given the following simple entity
@Entity
@Audited(withModifiedFlag = true)
public class SimpleEntity {
@Id
private Integer id;
@Column(name = "ENTITY_NAME")
private String name;
}
The Set<String>
would contain the String name
if that property was modified during a revision. It's important to note that the collection does not contain the column names, but instead the property names.

Naros
- 19,928
- 3
- 41
- 71