diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/boot/model/RootPersistentEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/boot/model/RootPersistentEntity.java index ffb0c5a03d..464ea0c7da 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/boot/model/RootPersistentEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/boot/model/RootPersistentEntity.java @@ -31,6 +31,7 @@ public class RootPersistentEntity extends PersistentEntity implements JoinAwareP private Identifier identifier; private String className; + private String entityName; private String tableName; private String whereClause; private DiscriminatorType discriminator; @@ -42,11 +43,12 @@ public class RootPersistentEntity extends PersistentEntity implements JoinAwareP this.joins = new ArrayList<>(); } - public RootPersistentEntity(AuditTableData auditTableData, String className, String tableName) { + public RootPersistentEntity(AuditTableData auditTableData, Class clazz, String entityName, String tableName) { super( auditTableData, null ); this.attributes = new ArrayList<>(); this.joins = new ArrayList<>(); - this.className = className; + this.className = clazz.getName(); + this.entityName = entityName; this.tableName = tableName; } @@ -116,6 +118,9 @@ public class RootPersistentEntity extends PersistentEntity implements JoinAwareP } else if ( !StringTools.isEmpty( className ) ) { entity.setName( className ); + if ( !StringTools.isEmpty( entityName ) ) { + entity.setEntityName( entityName ); + } } if ( !StringTools.isEmpty( getAuditTableData().getAuditTableName() ) ) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java index b887ab9acb..65aebbe3ae 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/RevisionInfoConfiguration.java @@ -165,7 +165,8 @@ public class RevisionInfoConfiguration { true, false, true, - revisionInfoEntityName ); + revisionInfoEntityName + ); attribute.setOnDelete( configuration.isCascadeDeleteRevision() ? "cascade" : null ); @@ -187,6 +188,7 @@ public class RevisionInfoConfiguration { private RootPersistentEntity generateDefaultRevisionInfoMapping(String revisionInfoIdName) { RootPersistentEntity mapping = new RootPersistentEntity( new AuditTableData( null, null, configuration.getDefaultSchemaName(), configuration.getDefaultCatalogName() ), + revisionInfoClass, revisionInfoEntityName, DEFAULT_REVISION_ENTITY_TABLE_NAME ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractMetadataGenerator.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractMetadataGenerator.java index b124fb3b85..67b8f732f4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractMetadataGenerator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/AbstractMetadataGenerator.java @@ -111,7 +111,7 @@ public abstract class AbstractMetadataGenerator { entity, metadataBuildingContext.getConfiguration(), metadataBuildingContext.getConfiguration().getRevisionTypePropertyType(), - metadataBuildingContext.getConfiguration().getRevisionInfo().getRevisionInfoClass().getName(), + metadataBuildingContext.getConfiguration().getRevisionInfo().getRevisionInfoEntityName(), false ) ); @@ -125,7 +125,7 @@ public abstract class AbstractMetadataGenerator { entity, metadataBuildingContext.getConfiguration(), metadataBuildingContext.getConfiguration().getRevisionTypePropertyType(), - metadataBuildingContext.getConfiguration().getRevisionInfo().getRevisionInfoClass().getName(), + metadataBuildingContext.getConfiguration().getRevisionInfo().getRevisionInfoEntityName(), true ) ); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StrictJpaComplianceTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StrictJpaComplianceTest.java new file mode 100644 index 0000000000..e2e2100661 --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/StrictJpaComplianceTest.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.envers.test.integration.query; + +import java.util.Map; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.envers.AuditReaderFactory; +import org.hibernate.envers.Audited; +import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; + +import org.hibernate.testing.transaction.TransactionUtil; +import org.junit.Test; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@SuppressWarnings("unchecked") +public class StrictJpaComplianceTest extends BaseEnversJPAFunctionalTestCase { + @Override + protected void addConfigOptions(Map options) { + super.addConfigOptions( options ); + options.put( AvailableSettings.JPA_QUERY_COMPLIANCE, "true" ); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Organization.class + }; + } + + @Test + public void testIt() { + TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> { + AuditReaderFactory.get( entityManager ).getRevisions( Organization.class, 1 ); + } ); + + } + + /** + * @author Madhumita Sadhukhan + */ + @Entity + @Table(name = "ORG") + public static class Organization { + + @Id + @GeneratedValue + @Audited + private int id; + + @Audited + @Column(name = "ORG_NAME") + private String name; + + public Organization() { + } + + } +}