diff --git a/documentation/src/main/docbook/devguide/en-US/Envers.xml b/documentation/src/main/docbook/devguide/en-US/Envers.xml index 2f04dc4469..7f9f05cb37 100644 --- a/documentation/src/main/docbook/devguide/en-US/Envers.xml +++ b/documentation/src/main/docbook/devguide/en-US/Envers.xml @@ -898,7 +898,9 @@ query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]> The minimize() and maximize() methods return a criteria, to which you can add constraints, which must be met by the entities with the - maximized/minimized properties. + maximized/minimized properties. AggregatedAuditExpression#computeAggregationInInstanceContext() + enables the possibility to compute aggregated expression in the context of each entity instance + separately. It turns out useful when querying for latest revisions of all entities of a particular type. diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java index ab8b84086b..bf6518417c 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java @@ -37,8 +37,7 @@ import org.hibernate.envers.tools.query.QueryBuilder; public class AggregatedAuditExpression implements AuditCriterion, ExtendableCriterion { private PropertyNameGetter propertyNameGetter; private AggregatedMode mode; - // Correlate subquery with outer query by entity id. - private boolean correlate = false; + private boolean correlate = false; // Correlate subquery with outer query by entity id. private List criterions; public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) { @@ -98,10 +97,12 @@ public class AggregatedAuditExpression implements AuditCriterion, ExtendableCrit } /** - * Correlates aggregated subquery with the main query by entity id. + * Compute aggregated expression in the context of each entity instance separately. Useful for retrieving latest + * revisions of all entities of a particular type.
+ * Implementation note: Correlates subquery with the outer query by entity id. * @return this (for method chaining). */ - public AggregatedAuditExpression correlateSubquery() { + public AggregatedAuditExpression computeAggregationInInstanceContext() { correlate = true; return this; } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java index 7efb33f301..764075cc45 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java @@ -189,7 +189,7 @@ public class MaximalizePropertyQuery extends BaseEnversJPAFunctionalTestCase { public void testAllLatestRevisionsOfEntityType() { List result = getAuditReader().createQuery() .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) - .add( AuditEntity.revisionNumber().maximize().correlateSubquery() ) + .add( AuditEntity.revisionNumber().maximize().computeAggregationInInstanceContext() ) .addOrder( AuditEntity.property( "id" ).asc() ) .getResultList();