HHH-11558 - Fix NullPointerException when using query api with non-audited entities.
This commit is contained in:
parent
47d6e40721
commit
a49790537c
|
@ -39,6 +39,7 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hernán Chanfreau
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public class AuditReaderImpl implements AuditReaderImplementor {
|
||||
private final EnversService enversService;
|
||||
|
@ -109,10 +110,6 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
checkPositive( revision, "Entity revision" );
|
||||
checkSession();
|
||||
|
||||
if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) {
|
||||
throw new NotAuditedException( entityName, entityName + " is not versioned!" );
|
||||
}
|
||||
|
||||
if ( firstLevelCache.contains( entityName, revision, primaryKey ) ) {
|
||||
return (T) firstLevelCache.get( entityName, revision, primaryKey );
|
||||
}
|
||||
|
@ -157,10 +154,6 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
checkNotNull( primaryKey, "Primary key" );
|
||||
checkSession();
|
||||
|
||||
if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) {
|
||||
throw new NotAuditedException( entityName, entityName + " is not versioned!" );
|
||||
}
|
||||
|
||||
return createQuery().forRevisionsOfEntity( cls, entityName, false, true )
|
||||
.addProjection( AuditEntity.revisionNumber() )
|
||||
.addOrder( AuditEntity.revisionNumber().asc() )
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.envers.query;
|
||||
|
||||
import org.hibernate.envers.boot.internal.EnversService;
|
||||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery;
|
||||
import org.hibernate.envers.query.internal.impl.EntitiesModifiedAtRevisionQuery;
|
||||
|
@ -20,6 +21,7 @@ import static org.hibernate.envers.internal.tools.EntityTools.getTargetClassIfPr
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author HernпїЅn Chanfreau
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
public class AuditQueryCreator {
|
||||
private final EnversService enversService;
|
||||
|
@ -45,6 +47,7 @@ public class AuditQueryCreator {
|
|||
checkNotNull( revision, "Entity revision" );
|
||||
checkPositive( revision, "Entity revision" );
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( c.getName() );
|
||||
return new EntitiesAtRevisionQuery( enversService, auditReaderImplementor, c, revision, false );
|
||||
}
|
||||
|
||||
|
@ -82,6 +85,7 @@ public class AuditQueryCreator {
|
|||
checkNotNull( revision, "Entity revision" );
|
||||
checkPositive( revision, "Entity revision" );
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( entityName );
|
||||
return new EntitiesAtRevisionQuery(
|
||||
enversService,
|
||||
auditReaderImplementor,
|
||||
|
@ -111,6 +115,7 @@ public class AuditQueryCreator {
|
|||
checkNotNull( revision, "Entity revision" );
|
||||
checkPositive( revision, "Entity revision" );
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( entityName );
|
||||
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, entityName, revision );
|
||||
}
|
||||
|
||||
|
@ -132,6 +137,7 @@ public class AuditQueryCreator {
|
|||
checkNotNull( revision, "Entity revision" );
|
||||
checkPositive( revision, "Entity revision" );
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( c.getName() );
|
||||
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, revision );
|
||||
}
|
||||
|
||||
|
@ -159,6 +165,7 @@ public class AuditQueryCreator {
|
|||
*/
|
||||
public AuditQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( c.getName() );
|
||||
return new RevisionsOfEntityQuery(
|
||||
enversService,
|
||||
auditReaderImplementor,
|
||||
|
@ -197,6 +204,7 @@ public class AuditQueryCreator {
|
|||
boolean selectEntitiesOnly,
|
||||
boolean selectDeletedEntities) {
|
||||
c = getTargetClassIfProxied( c );
|
||||
checkEntityAudited( entityName );
|
||||
return new RevisionsOfEntityQuery(
|
||||
enversService,
|
||||
auditReaderImplementor,
|
||||
|
@ -206,4 +214,13 @@ public class AuditQueryCreator {
|
|||
selectDeletedEntities
|
||||
);
|
||||
}
|
||||
|
||||
private void checkEntityAudited(String entityName) {
|
||||
if ( !auditReaderImplementor.isEntityNameAudited( entityName ) ) {
|
||||
throw new NotAuditedException(
|
||||
entityName,
|
||||
"Cannot query audit history on a non-audited entity [" + entityName + "]."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue