diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
index 236efa91f2..ee079f9a85 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
@@ -173,6 +173,7 @@ public class AuditQueryCreator {
c,
selectEntitiesOnly,
selectDeletedEntities,
+ false,
false
);
}
@@ -214,6 +215,7 @@ public class AuditQueryCreator {
entityName,
selectEntitiesOnly,
selectDeletedEntities,
+ false,
false
);
}
@@ -239,7 +241,8 @@ public class AuditQueryCreator {
clazz,
false,
selectDeletedEntities,
- true
+ true,
+ false
);
}
@@ -266,6 +269,75 @@ public class AuditQueryCreator {
entityName,
false,
selectDeletedEntities,
+ true,
+ false
+ );
+ }
+
+ /**
+ * Creates a query that selects the revisions at which the given entity was modified. Unless a
+ * projection is set, the result will be a list of 4-element arrays, containing the following:
+ *
+ *
The entity instance
+ *
Revision entity, corresponding to the revision where the entity was modified. If no custom
+ * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}.
+ *
The revision type, an enum of class {@link org.hibernate.envers.RevisionType}.
+ *
The names of the properties changed in this revision
+ *
+ * Additional criterion may be specified to filter the result set.
+ *
+ * @param clazz Class of the entities for which to query.
+ * @param selectDeletedEntities If true, the result set will include revisions where entities were deleted.
+ *
+ * @return the audit query
+ *
+ * @since 5.3
+ */
+ @Incubating
+ public AuditQuery forRevisionsOfEntityWithChanges(Class> clazz, boolean selectDeletedEntities) {
+ clazz = getTargetClassIfProxied( clazz );
+ return new RevisionsOfEntityQuery(
+ enversService,
+ auditReaderImplementor,
+ clazz,
+ false,
+ selectDeletedEntities,
+ false,
+ true
+ );
+ }
+
+ /**
+ * Creates a query that selects the revisions at which the given entity was modified. Unless a
+ * projection is set, the result will be a list of 4-element arrays, containing the following:
+ *
+ *
The entity instance
+ *
Revision entity, corresponding to the revision where the entity was modified. If no custom
+ * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}.
+ *
The revision type, an enum of class {@link org.hibernate.envers.RevisionType}.
+ *
The names of the properties changed in this revision
+ *
+ * Additional criterion may be specified to filter the result set.
+ *
+ * @param clazz Class of the entities for which to query.
+ * @param entityName Name of the entity (if it can't be guessed basing on the {@code clazz}).
+ * @param selectDeletedEntities If true, the result set will include revisions where entities were deleted.
+ *
+ * @return the audit query
+ *
+ * @since 5.3
+ */
+ @Incubating
+ public AuditQuery forRevisionsOfEntityWithChanges(Class> clazz, String entityName, boolean selectDeletedEntities) {
+ clazz = getTargetClassIfProxied( clazz );
+ return new RevisionsOfEntityQuery(
+ enversService,
+ auditReaderImplementor,
+ clazz,
+ entityName,
+ false,
+ selectDeletedEntities,
+ false,
true
);
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java
index e2e963d6ae..f26b9a741e 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/AbstractAuditQuery.java
@@ -22,6 +22,7 @@ import org.hibernate.LockOptions;
import org.hibernate.envers.boot.internal.EnversService;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.exception.NotAuditedException;
+import org.hibernate.envers.internal.entities.EntityConfiguration;
import org.hibernate.envers.internal.entities.EntityInstantiator;
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
import org.hibernate.envers.internal.tools.query.QueryBuilder;
@@ -341,4 +342,13 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor {
}
return result;
}
+
+ protected EntityConfiguration getEntityConfiguration() {
+ return enversService.getEntitiesConfigurations().get( entityName );
+ }
+
+ protected String getEntityName() {
+ // todo: can this be replaced by a call to getEntittyConfiguration#getEntityClassName()?
+ return entityName;
+ }
}
diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java
index af5cf0da54..78f9f24dd6 100644
--- a/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java
+++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/internal/impl/RevisionsOfEntityQuery.java
@@ -7,8 +7,11 @@
package org.hibernate.envers.query.internal.impl;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import javax.persistence.criteria.JoinType;
@@ -17,6 +20,8 @@ import org.hibernate.envers.RevisionType;
import org.hibernate.envers.boot.internal.EnversService;
import org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration;
import org.hibernate.envers.exception.AuditException;
+import org.hibernate.envers.internal.entities.PropertyData;
+import org.hibernate.envers.internal.entities.mapper.ExtendedPropertyMapper;
import org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants;
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
import org.hibernate.envers.query.AuditAssociationQuery;
@@ -32,6 +37,7 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
private final boolean selectEntitiesOnly;
private final boolean selectDeletedEntities;
private final boolean selectRevisionInfoOnly;
+ private final boolean includePropertyChanges;
public RevisionsOfEntityQuery(
EnversService enversService,
@@ -39,12 +45,14 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
Class> cls,
boolean selectEntitiesOnly,
boolean selectDeletedEntities,
- boolean selectRevisionInfoOnly) {
+ boolean selectRevisionInfoOnly,
+ boolean includePropertyChanges) {
super( enversService, versionsReader, cls );
this.selectEntitiesOnly = selectEntitiesOnly;
this.selectDeletedEntities = selectDeletedEntities;
this.selectRevisionInfoOnly = selectRevisionInfoOnly && !selectEntitiesOnly;
+ this.includePropertyChanges = includePropertyChanges;
}
public RevisionsOfEntityQuery(
@@ -53,12 +61,14 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
Class> cls, String entityName,
boolean selectEntitiesOnly,
boolean selectDeletedEntities,
- boolean selectRevisionInfoOnly) {
+ boolean selectRevisionInfoOnly,
+ boolean includePropertyChanges) {
super( enversService, versionsReader, cls, entityName );
this.selectEntitiesOnly = selectEntitiesOnly;
this.selectDeletedEntities = selectDeletedEntities;
this.selectRevisionInfoOnly = selectRevisionInfoOnly && !selectEntitiesOnly;
+ this.includePropertyChanges = includePropertyChanges;
}
private Number getRevisionNumber(Map versionsEntity) {
@@ -123,49 +133,7 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
);
}
- List