HHH-12018 - Revert fix for HHH-11841: Audit query QueryException on maps using entity-types as keys.
This commit is contained in:
parent
2ace60ea79
commit
dd2bf67ac9
|
@ -76,6 +76,7 @@ import org.hibernate.mapping.Table;
|
|||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.type.BagType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.CustomType;
|
||||
import org.hibernate.type.ListType;
|
||||
import org.hibernate.type.ManyToOneType;
|
||||
import org.hibernate.type.MapType;
|
||||
|
@ -448,8 +449,7 @@ public final class CollectionMetadataGenerator {
|
|||
mainGenerator.getAuditStrategy(),
|
||||
referencingIdData,
|
||||
auditMiddleEntityName,
|
||||
isKeyRevisionTypeInId(),
|
||||
isElementRevisionTypeInId()
|
||||
isRevisionTypeInId()
|
||||
);
|
||||
|
||||
// Adding the XML mapping for the referencing entity, if the relation isn't inverse.
|
||||
|
@ -471,7 +471,7 @@ public final class CollectionMetadataGenerator {
|
|||
queryGeneratorBuilder,
|
||||
referencedPrefix,
|
||||
propertyAuditingData.getJoinTable().inverseJoinColumns(),
|
||||
!isLobMapElementType() && isMapElementInPrimaryKey()
|
||||
!isLobMapElementType()
|
||||
);
|
||||
|
||||
// ******
|
||||
|
@ -855,9 +855,9 @@ public final class CollectionMetadataGenerator {
|
|||
|
||||
// Adding the revision type property to the entity xml.
|
||||
mainGenerator.addRevisionType(
|
||||
isElementRevisionTypeInId() ? middleEntityXmlId : middleEntityXml,
|
||||
isRevisionTypeInId() ? middleEntityXmlId : middleEntityXml,
|
||||
middleEntityXml,
|
||||
isElementRevisionTypeInId()
|
||||
isRevisionTypeInId()
|
||||
);
|
||||
|
||||
// All other properties should also be part of the primary key of the middle entity.
|
||||
|
@ -1028,7 +1028,7 @@ public final class CollectionMetadataGenerator {
|
|||
*
|
||||
* @return {@code true} if the revision type should be part of the primary key, otherwise {@code false}.
|
||||
*/
|
||||
private boolean isElementRevisionTypeInId() {
|
||||
private boolean isRevisionTypeInId() {
|
||||
return isEmbeddableElementType() || isLobMapElementType();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ public final class QueryGeneratorBuilder {
|
|||
private final MiddleIdData referencingIdData;
|
||||
private final String auditMiddleEntityName;
|
||||
private final List<MiddleIdData> idDatas;
|
||||
private final boolean elementRevisionTypeInId;
|
||||
private final boolean keyRevisionTypeInId;
|
||||
private final boolean revisionTypeInId;
|
||||
|
||||
QueryGeneratorBuilder(
|
||||
GlobalConfiguration globalCfg,
|
||||
|
@ -44,15 +43,13 @@ public final class QueryGeneratorBuilder {
|
|||
AuditStrategy auditStrategy,
|
||||
MiddleIdData referencingIdData,
|
||||
String auditMiddleEntityName,
|
||||
boolean keyRevisionTypeInId,
|
||||
boolean elementRevisionTypeInId) {
|
||||
boolean revisionTypeInId) {
|
||||
this.globalCfg = globalCfg;
|
||||
this.verEntCfg = verEntCfg;
|
||||
this.auditStrategy = auditStrategy;
|
||||
this.referencingIdData = referencingIdData;
|
||||
this.auditMiddleEntityName = auditMiddleEntityName;
|
||||
this.keyRevisionTypeInId = keyRevisionTypeInId;
|
||||
this.elementRevisionTypeInId = elementRevisionTypeInId;
|
||||
this.revisionTypeInId = revisionTypeInId;
|
||||
|
||||
idDatas = new ArrayList<>();
|
||||
}
|
||||
|
@ -65,20 +62,20 @@ public final class QueryGeneratorBuilder {
|
|||
if ( idDatas.size() == 0 ) {
|
||||
return new OneEntityQueryGenerator(
|
||||
verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
|
||||
elementRevisionTypeInId, componentDatas
|
||||
revisionTypeInId, componentDatas
|
||||
);
|
||||
}
|
||||
else if ( idDatas.size() == 1 ) {
|
||||
if ( idDatas.get( 0 ).isAudited() ) {
|
||||
return new TwoEntityQueryGenerator(
|
||||
globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
|
||||
idDatas.get( 0 ), elementRevisionTypeInId, keyRevisionTypeInId, componentDatas
|
||||
idDatas.get( 0 ), revisionTypeInId, componentDatas
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new TwoEntityOneAuditedQueryGenerator(
|
||||
verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
|
||||
idDatas.get( 0 ), elementRevisionTypeInId, componentDatas
|
||||
idDatas.get( 0 ), revisionTypeInId, componentDatas
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +89,7 @@ public final class QueryGeneratorBuilder {
|
|||
|
||||
return new ThreeEntityQueryGenerator(
|
||||
globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
|
||||
idDatas.get( 0 ), idDatas.get( 1 ), elementRevisionTypeInId, componentDatas
|
||||
idDatas.get( 0 ), idDatas.get( 1 ), revisionTypeInId, componentDatas
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -29,18 +29,15 @@ import static org.hibernate.envers.internal.entities.mapper.relation.query.Query
|
|||
public abstract class AbstractRelationQueryGenerator implements RelationQueryGenerator {
|
||||
protected final AuditEntitiesConfiguration verEntCfg;
|
||||
protected final MiddleIdData referencingIdData;
|
||||
protected final boolean keyRevisionTypeInId;
|
||||
protected final boolean elementRevisionTypeInId;
|
||||
protected final boolean revisionTypeInId;
|
||||
|
||||
protected AbstractRelationQueryGenerator(
|
||||
AuditEntitiesConfiguration verEntCfg,
|
||||
MiddleIdData referencingIdData,
|
||||
boolean keyRevisionTypeInId,
|
||||
boolean elementRevisionTypeInId) {
|
||||
boolean revisionTypeInId) {
|
||||
this.verEntCfg = verEntCfg;
|
||||
this.referencingIdData = referencingIdData;
|
||||
this.keyRevisionTypeInId = keyRevisionTypeInId;
|
||||
this.elementRevisionTypeInId = elementRevisionTypeInId;
|
||||
this.revisionTypeInId = revisionTypeInId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,14 +65,6 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen
|
|||
return query;
|
||||
}
|
||||
|
||||
protected String getElementRevisionTypePath() {
|
||||
return getRevisionTypePath( this.elementRevisionTypeInId );
|
||||
}
|
||||
|
||||
protected String getKeyRevisionTypePath() {
|
||||
return getRevisionTypePath( this.keyRevisionTypeInId );
|
||||
}
|
||||
|
||||
protected String queryToString(QueryBuilder query) {
|
||||
return queryToString( query, Collections.emptyMap() );
|
||||
}
|
||||
|
@ -86,7 +75,7 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getRevisionTypePath(boolean revisionTypeInId) {
|
||||
protected String getRevisionTypePath() {
|
||||
return revisionTypeInId
|
||||
? verEntCfg.getOriginalIdPropName() + "." + verEntCfg.getRevisionTypePropName()
|
||||
: verEntCfg.getRevisionTypePropName();
|
||||
|
|
|
@ -43,7 +43,7 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen
|
|||
boolean revisionTypeInId,
|
||||
String mappedBy,
|
||||
boolean mappedByKey) {
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId, revisionTypeInId );
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId );
|
||||
|
||||
this.mappedBy = mappedBy;
|
||||
|
||||
|
@ -124,7 +124,7 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen
|
|||
true
|
||||
);
|
||||
// e.revision_type != DEL
|
||||
rootParameters.addWhereWithNamedParam( getElementRevisionTypePath(), false, "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
rootParameters.addWhereWithNamedParam( getRevisionTypePath(), false, "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,7 +143,7 @@ public final class OneAuditEntityQueryGenerator extends AbstractRelationQueryGen
|
|||
// e.revision = :revision
|
||||
removed.addWhereWithNamedParam( verEntCfg.getRevisionNumberPath(), false, "=", REVISION_PARAMETER );
|
||||
// e.revision_type = DEL
|
||||
removed.addWhereWithNamedParam( getElementRevisionTypePath(), false, "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
removed.addWhereWithNamedParam( getRevisionTypePath(), false, "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy,
|
||||
String versionsMiddleEntityName, MiddleIdData referencingIdData,
|
||||
boolean revisionTypeInId, MiddleComponentData... componentData) {
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId, revisionTypeInId );
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId );
|
||||
|
||||
/*
|
||||
* The valid query that we need to create:
|
||||
|
@ -99,7 +99,7 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
originalIdPropertyName, MIDDLE_ENTITY_ALIAS, inclusive, componentData
|
||||
);
|
||||
// ee.revision_type != DEL
|
||||
rootParameters.addWhereWithNamedParam( getElementRevisionTypePath(), "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
rootParameters.addWhereWithNamedParam( getRevisionTypePath(), "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,7 +118,7 @@ public final class OneEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
// ee.revision = :revision
|
||||
removed.addWhereWithNamedParam( verEntCfg.getRevisionNumberPath(), "=", REVISION_PARAMETER );
|
||||
// ee.revision_type = DEL
|
||||
removed.addWhereWithNamedParam( getElementRevisionTypePath(), "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
removed.addWhereWithNamedParam( getRevisionTypePath(), "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera
|
|||
MiddleIdData referencingIdData, MiddleIdData referencedIdData,
|
||||
MiddleIdData indexIdData, boolean revisionTypeInId,
|
||||
MiddleComponentData... componentData) {
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId, revisionTypeInId );
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId );
|
||||
|
||||
/*
|
||||
* The valid query that we need to create:
|
||||
|
@ -148,7 +148,7 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera
|
|||
final String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
final String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
|
||||
final String revisionTypePropName = getElementRevisionTypePath();
|
||||
final String revisionTypePropName = getRevisionTypePath();
|
||||
// (selecting e entities at revision :revision)
|
||||
// --> based on auditStrategy (see above)
|
||||
auditStrategy.addEntityAtRevisionRestriction(
|
||||
|
@ -219,7 +219,7 @@ public final class ThreeEntityQueryGenerator extends AbstractRelationQueryGenera
|
|||
// Restrictions to match all rows deleted at exactly given revision.
|
||||
final Parameters removed = disjoint.addSubParameters( "and" );
|
||||
final String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
final String revisionTypePropName = getElementRevisionTypePath();
|
||||
final String revisionTypePropName = getRevisionTypePath();
|
||||
// Excluding current revision, because we need to match data valid at the previous one.
|
||||
createValidDataRestrictions(
|
||||
globalCfg, auditStrategy, referencedIdData, versionsMiddleEntityName, remQb, valid, false, indexIdData, componentData
|
||||
|
|
|
@ -31,9 +31,9 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue
|
|||
public TwoEntityOneAuditedQueryGenerator(
|
||||
AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy,
|
||||
String versionsMiddleEntityName, MiddleIdData referencingIdData,
|
||||
MiddleIdData referencedIdData, boolean elementRevisionTypeInId,
|
||||
MiddleIdData referencedIdData, boolean revisionTypeInId,
|
||||
MiddleComponentData... componentData) {
|
||||
super( verEntCfg, referencingIdData, elementRevisionTypeInId, elementRevisionTypeInId );
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId );
|
||||
|
||||
/*
|
||||
* The valid query that we need to create:
|
||||
|
@ -112,7 +112,7 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue
|
|||
originalIdPropertyName, MIDDLE_ENTITY_ALIAS, true, componentData
|
||||
);
|
||||
// ee.revision_type != DEL
|
||||
rootParameters.addWhereWithNamedParam( getElementRevisionTypePath(), "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
rootParameters.addWhereWithNamedParam( getRevisionTypePath(), "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +130,7 @@ public final class TwoEntityOneAuditedQueryGenerator extends AbstractRelationQue
|
|||
// ee.revision = :revision
|
||||
removed.addWhereWithNamedParam( verEntCfg.getRevisionNumberPath(), "=", REVISION_PARAMETER );
|
||||
// ee.revision_type = DEL
|
||||
removed.addWhereWithNamedParam( getElementRevisionTypePath(), "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
removed.addWhereWithNamedParam( getRevisionTypePath(), "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,8 +34,8 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
|
||||
AuditStrategy auditStrategy, String versionsMiddleEntityName,
|
||||
MiddleIdData referencingIdData, MiddleIdData referencedIdData,
|
||||
boolean elementRevisionTypeInId, boolean keyRevisionTypeInId, MiddleComponentData... componentData) {
|
||||
super( verEntCfg, referencingIdData, keyRevisionTypeInId, elementRevisionTypeInId );
|
||||
boolean revisionTypeInId, MiddleComponentData... componentData) {
|
||||
super( verEntCfg, referencingIdData, revisionTypeInId );
|
||||
|
||||
/*
|
||||
* The valid query that we need to create:
|
||||
|
@ -120,7 +120,7 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
final String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
final String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
|
||||
final String revisionTypePropName = getElementRevisionTypePath();
|
||||
final String revisionTypePropName = getRevisionTypePath();
|
||||
// (selecting e entities at revision :revision)
|
||||
// --> based on auditStrategy (see above)
|
||||
auditStrategy.addEntityAtRevisionRestriction(
|
||||
|
@ -149,7 +149,7 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
rootParameters.addWhereWithNamedParam( revisionTypePropName, "!=", DEL_REVISION_TYPE_PARAMETER );
|
||||
// e.revision_type != DEL
|
||||
rootParameters.addWhereWithNamedParam(
|
||||
REFERENCED_ENTITY_ALIAS + "." + getKeyRevisionTypePath(),
|
||||
REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName,
|
||||
false,
|
||||
"!=",
|
||||
DEL_REVISION_TYPE_PARAMETER
|
||||
|
@ -169,7 +169,7 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
// Restrictions to match all rows deleted at exactly given revision.
|
||||
final Parameters removed = disjoint.addSubParameters( "and" );
|
||||
final String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
final String revisionTypePropName = getElementRevisionTypePath();
|
||||
final String revisionTypePropName = getRevisionTypePath();
|
||||
// Excluding current revision, because we need to match data valid at the previous one.
|
||||
createValidDataRestrictions(
|
||||
globalCfg,
|
||||
|
@ -194,7 +194,7 @@ public final class TwoEntityQueryGenerator extends AbstractRelationQueryGenerato
|
|||
removed.addWhereWithNamedParam( revisionTypePropName, "=", DEL_REVISION_TYPE_PARAMETER );
|
||||
// e.revision_type = DEL
|
||||
removed.addWhereWithNamedParam(
|
||||
REFERENCED_ENTITY_ALIAS + "." + getKeyRevisionTypePath(),
|
||||
REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName,
|
||||
false,
|
||||
"=",
|
||||
DEL_REVISION_TYPE_PARAMETER
|
||||
|
|
|
@ -19,6 +19,8 @@ import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase;
|
|||
import org.hibernate.envers.test.Priority;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -27,6 +29,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
/**
|
||||
* @author Chris Cranford
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-11841")
|
||||
public class EntityMapCompositeElementTest extends BaseEnversJPAFunctionalTestCase {
|
||||
|
||||
private Category category;
|
||||
|
@ -51,6 +54,7 @@ public class EntityMapCompositeElementTest extends BaseEnversJPAFunctionalTestCa
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected(jiraKey = "HHH-11841", message = "Reverted fix in HHH-12018 and will be fixed in HHH-12043")
|
||||
public void testRevisionHistory() {
|
||||
final AuditReader reader = getAuditReader();
|
||||
|
||||
|
|
Loading…
Reference in New Issue