diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/InheritanceAssociationToOneInnerJoinTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/InheritanceAssociationToOneInnerJoinTest.java index d98860b871..72da455a2c 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/InheritanceAssociationToOneInnerJoinTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/InheritanceAssociationToOneInnerJoinTest.java @@ -110,6 +110,21 @@ public class InheritanceAssociationToOneInnerJoinTest extends BaseEnversJPAFunct assertEquals( 2, results.size() ); } + @Test + public void testAuditQueryWithJoinedInheritanceSubclassPropertyProjectionWithRelationTraversal() { + // HHH-11383 + // This test was requested by the reporter so that we have a test that shows Hibernate is + // automatically adding "INNER JOIN EntityA_AUD" despite the fact whether the query uses + // the traverseRelation API or not. This test makes sure that if the SQL generation is + // changed in the future, Envers would properly fail if so. + List results = getAuditReader().createQuery().forEntitiesAtRevision( EntityB.class, 1 ) + .addProjection( property( "name" ) ) + .traverseRelation( "relationToC", JoinType.INNER ) + .add( property( "foo" ).like( "bar" ) ) + .getResultList(); + assertEquals( 2, results.size() ); + } + @Entity(name = "EntityA") @Audited @Inheritance(strategy = InheritanceType.JOINED)