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 Adam Warski (adam at warski dot org)
|
||||||
* @author Hernán Chanfreau
|
* @author Hernán Chanfreau
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
* @author Chris Cranford
|
||||||
*/
|
*/
|
||||||
public class AuditReaderImpl implements AuditReaderImplementor {
|
public class AuditReaderImpl implements AuditReaderImplementor {
|
||||||
private final EnversService enversService;
|
private final EnversService enversService;
|
||||||
|
@ -109,10 +110,6 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
||||||
checkPositive( revision, "Entity revision" );
|
checkPositive( revision, "Entity revision" );
|
||||||
checkSession();
|
checkSession();
|
||||||
|
|
||||||
if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) {
|
|
||||||
throw new NotAuditedException( entityName, entityName + " is not versioned!" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( firstLevelCache.contains( entityName, revision, primaryKey ) ) {
|
if ( firstLevelCache.contains( entityName, revision, primaryKey ) ) {
|
||||||
return (T) firstLevelCache.get( entityName, revision, primaryKey );
|
return (T) firstLevelCache.get( entityName, revision, primaryKey );
|
||||||
}
|
}
|
||||||
|
@ -157,10 +154,6 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
||||||
checkNotNull( primaryKey, "Primary key" );
|
checkNotNull( primaryKey, "Primary key" );
|
||||||
checkSession();
|
checkSession();
|
||||||
|
|
||||||
if ( !enversService.getEntitiesConfigurations().isVersioned( entityName ) ) {
|
|
||||||
throw new NotAuditedException( entityName, entityName + " is not versioned!" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return createQuery().forRevisionsOfEntity( cls, entityName, false, true )
|
return createQuery().forRevisionsOfEntity( cls, entityName, false, true )
|
||||||
.addProjection( AuditEntity.revisionNumber() )
|
.addProjection( AuditEntity.revisionNumber() )
|
||||||
.addOrder( AuditEntity.revisionNumber().asc() )
|
.addOrder( AuditEntity.revisionNumber().asc() )
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.envers.query;
|
package org.hibernate.envers.query;
|
||||||
|
|
||||||
import org.hibernate.envers.boot.internal.EnversService;
|
import org.hibernate.envers.boot.internal.EnversService;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||||
import org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery;
|
import org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery;
|
||||||
import org.hibernate.envers.query.internal.impl.EntitiesModifiedAtRevisionQuery;
|
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 Adam Warski (adam at warski dot org)
|
||||||
* @author HernпїЅn Chanfreau
|
* @author HernпїЅn Chanfreau
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
* @author Chris Cranford
|
||||||
*/
|
*/
|
||||||
public class AuditQueryCreator {
|
public class AuditQueryCreator {
|
||||||
private final EnversService enversService;
|
private final EnversService enversService;
|
||||||
|
@ -45,6 +47,7 @@ public class AuditQueryCreator {
|
||||||
checkNotNull( revision, "Entity revision" );
|
checkNotNull( revision, "Entity revision" );
|
||||||
checkPositive( revision, "Entity revision" );
|
checkPositive( revision, "Entity revision" );
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( c.getName() );
|
||||||
return new EntitiesAtRevisionQuery( enversService, auditReaderImplementor, c, revision, false );
|
return new EntitiesAtRevisionQuery( enversService, auditReaderImplementor, c, revision, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +85,7 @@ public class AuditQueryCreator {
|
||||||
checkNotNull( revision, "Entity revision" );
|
checkNotNull( revision, "Entity revision" );
|
||||||
checkPositive( revision, "Entity revision" );
|
checkPositive( revision, "Entity revision" );
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( entityName );
|
||||||
return new EntitiesAtRevisionQuery(
|
return new EntitiesAtRevisionQuery(
|
||||||
enversService,
|
enversService,
|
||||||
auditReaderImplementor,
|
auditReaderImplementor,
|
||||||
|
@ -111,6 +115,7 @@ public class AuditQueryCreator {
|
||||||
checkNotNull( revision, "Entity revision" );
|
checkNotNull( revision, "Entity revision" );
|
||||||
checkPositive( revision, "Entity revision" );
|
checkPositive( revision, "Entity revision" );
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( entityName );
|
||||||
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, entityName, revision );
|
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, entityName, revision );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +137,7 @@ public class AuditQueryCreator {
|
||||||
checkNotNull( revision, "Entity revision" );
|
checkNotNull( revision, "Entity revision" );
|
||||||
checkPositive( revision, "Entity revision" );
|
checkPositive( revision, "Entity revision" );
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( c.getName() );
|
||||||
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, revision );
|
return new EntitiesModifiedAtRevisionQuery( enversService, auditReaderImplementor, c, revision );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +165,7 @@ public class AuditQueryCreator {
|
||||||
*/
|
*/
|
||||||
public AuditQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
|
public AuditQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( c.getName() );
|
||||||
return new RevisionsOfEntityQuery(
|
return new RevisionsOfEntityQuery(
|
||||||
enversService,
|
enversService,
|
||||||
auditReaderImplementor,
|
auditReaderImplementor,
|
||||||
|
@ -197,6 +204,7 @@ public class AuditQueryCreator {
|
||||||
boolean selectEntitiesOnly,
|
boolean selectEntitiesOnly,
|
||||||
boolean selectDeletedEntities) {
|
boolean selectDeletedEntities) {
|
||||||
c = getTargetClassIfProxied( c );
|
c = getTargetClassIfProxied( c );
|
||||||
|
checkEntityAudited( entityName );
|
||||||
return new RevisionsOfEntityQuery(
|
return new RevisionsOfEntityQuery(
|
||||||
enversService,
|
enversService,
|
||||||
auditReaderImplementor,
|
auditReaderImplementor,
|
||||||
|
@ -206,4 +214,13 @@ public class AuditQueryCreator {
|
||||||
selectDeletedEntities
|
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