From 877a05213cc6078400d6f9356bcb8e113e670651 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 24 Oct 2016 16:14:11 +0200 Subject: [PATCH] Fix failing WithClauseTest --- .../hibernate/test/hql/WithClauseTest.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java index c4942ba234..3589a62fc1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java @@ -227,22 +227,27 @@ public void testWithClauseAsSubqueryWithKey() { public void testWithClauseAsNonSubqueryWithKey() { rebuildSessionFactory( Collections.singletonMap( AvailableSettings.COLLECTION_JOIN_SUBQUERY, "false" ) ); - TestData data = new TestData(); - data.prepare(); + try { + TestData data = new TestData(); + data.prepare(); - Session s = openSession(); - Transaction txn = s.beginTransaction(); + Session s = openSession(); + Transaction txn = s.beginTransaction(); - // Since family has a join table, we will first left join all family members and then do the WITH clause on the target entity table join - // Normally this produces 2 results which is wrong and can only be circumvented by converting the join table and target entity table join to a subquery - List list = s.createQuery("from Human h left join h.family as f with key(f) like 'son1' where h.description = 'father'") - .list(); - assertEquals("subquery rewriting of join table was not disabled", 2, list.size()); + // Since family has a join table, we will first left join all family members and then do the WITH clause on the target entity table join + // Normally this produces 2 results which is wrong and can only be circumvented by converting the join table and target entity table join to a subquery + List list = s.createQuery( "from Human h left join h.family as f with key(f) like 'son1' where h.description = 'father'" ) + .list(); + assertEquals( "subquery rewriting of join table was not disabled", 2, list.size() ); - txn.commit(); - s.close(); + txn.commit(); + s.close(); - data.cleanup(); + data.cleanup(); + } finally { + // Rebuild to reset the properties + rebuildSessionFactory(); + } } private class TestData {