diff --git a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java index ed578f3c12..159f21d5c7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java @@ -31,6 +31,7 @@ import org.hibernate.dialect.IngresDialect; import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.query.Query; import org.hibernate.transform.DistinctRootEntityResultTransformer; import org.hibernate.testing.SkipForDialect; @@ -38,6 +39,7 @@ import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; @@ -213,6 +215,29 @@ public class DynamicFilterTest extends BaseNonConfigCoreFunctionalTestCase { testData.release(); } + @Test + @TestForIssue(jiraKey = "HHH-14567") + public void testHqlFiltersAppliedAfterQueryCreation() { + TestData testData = new TestData(); + testData.prepare(); + + try { + inTransaction( session -> { + Query query = session.createQuery( + "select s from Salesperson s", + Salesperson.class + ); + assertThat( query.list() ).hasSize( 2 ); + + session.enableFilter( "region" ).setParameter( "region", "APAC" ); + assertThat( query.list() ).hasSize( 1 ); + } ); + } + finally { + testData.release(); + } + } + @Test public void testFiltersWithCustomerReadAndWrite() { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/test/java/org/hibernate/test/filter/Salesperson.java b/hibernate-core/src/test/java/org/hibernate/test/filter/Salesperson.java index 38d9342d71..059ee4e884 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/filter/Salesperson.java +++ b/hibernate-core/src/test/java/org/hibernate/test/filter/Salesperson.java @@ -24,6 +24,13 @@ public class Salesperson { private Department department; private Set orders = new HashSet(); + @Override + public String toString() { + return "Salesperson#" + id + "{" + + ", name='" + name + '\'' + + '}'; + } + public Long getId() { return id; }