diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java index 94c61bc5b1..498a8ff22d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditReader.java @@ -71,7 +71,7 @@ public interface AuditReader { T find(Class cls, String entityName, Object primaryKey, Number revision) throws IllegalArgumentException, NotAuditedException, IllegalStateException; - + /** * Find an entity by primary key at the given revision with the specified entityName, * possibly including deleted entities in the search. 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 895abeb59f..0bd8c4f063 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 @@ -49,7 +49,7 @@ public class AuditQueryCreator { /** * Creates a query, which will return entities satisfying some conditions (specified later), - * at a given revision. + * at a given revision. Deleted entities are not included. * @param c Class of the entities for which to query. * @param revision Revision number at which to execute the query. * @return A query for entities at a given revision, to which conditions can be added and which @@ -60,12 +60,12 @@ public class AuditQueryCreator { checkNotNull(revision, "Entity revision"); checkPositive(revision, "Entity revision"); c = getTargetClassIfProxied(c); - return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision); + return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision, false); } /** * Creates a query, which will return entities satisfying some conditions (specified later), - * at a given revision and a given entityName. + * at a given revision and a given entityName. Deleted entities are not included. * @param c Class of the entities for which to query. * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). * @param revision Revision number at which to execute the query. @@ -74,10 +74,7 @@ public class AuditQueryCreator { * projection is added. */ public AuditQuery forEntitiesAtRevision(Class c, String entityName, Number revision) { - checkNotNull(revision, "Entity revision"); - checkPositive(revision, "Entity revision"); - c = getTargetClassIfProxied(c); - return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, entityName, revision); + return forEntitiesAtRevision(c, entityName, revision, false); } /** diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java index 8e98b47cb8..e2df3aafe2 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java @@ -49,18 +49,11 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { public EntitiesAtRevisionQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Class cls, - Number revision) { + Number revision, boolean includeDeletions) { super(verCfg, versionsReader, cls); this.revision = revision; - this.includeDeletions = false; + this.includeDeletions = includeDeletions; } - - public EntitiesAtRevisionQuery(AuditConfiguration verCfg, - AuditReaderImplementor versionsReader, Class cls, String entityName, Number revision) { - super(verCfg, versionsReader, cls, entityName); - this.revision = revision; - this.includeDeletions = false; - } public EntitiesAtRevisionQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader, Class cls, @@ -101,9 +94,9 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery { verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencedIdData, revisionPropertyPath, originalIdPropertyName, REFERENCED_ENTITY_ALIAS, REFERENCED_ENTITY_ALIAS_DEF_AUD_STR); - - // e.revision_type != DEL + if (!includeDeletions) { + // e.revision_type != DEL qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL); }