From 140de50a954277e235fcbc08fa6332ad8ac29dab Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 25 Jan 2017 19:58:34 +0100 Subject: [PATCH] Test for HHH-10537 (cherry picked from commit 72382b1e08dd64eae9191aada2301e2f76c8ce96) --- .../CollectionMapWithComponentValueTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java index bd0bcd643a..9ee314bbc7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CollectionMapWithComponentValueTest.java @@ -11,11 +11,14 @@ import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.Table; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.hibernate.Query; import org.hibernate.Session; @@ -42,6 +45,7 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC @Override protected Class[] getAnnotatedClasses() { return new Class[] { + BaseTestEntity.class, TestEntity.class, KeyValue.class }; @@ -54,14 +58,20 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC { s.save( keyValue ); + BaseTestEntity baseTestEntity1 = new BaseTestEntity(); TestEntity testEntity = new TestEntity(); Map map = new HashMap<>(); map.put( keyValue, embeddableValue ); testEntity.values = map; s.save( testEntity ); + baseTestEntity1.entities = new HashSet(); + baseTestEntity1.entities.add( testEntity ); + s.save( baseTestEntity1 ); KeyValue keyValue2 = new KeyValue( "key2" ); s.save( keyValue2 ); + BaseTestEntity baseTestEntity2 = new BaseTestEntity(); + s.save( baseTestEntity2 ); TestEntity testEntity2 = new TestEntity(); Map map2 = new HashMap<>(); map.put( keyValue2, embeddableValue ); @@ -203,11 +213,32 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC s.close(); } + @Test + @TestForIssue(jiraKey = "HHH-10537") + public void testLeftJoinMapAndUseKeyExpression() { + doInHibernate( this::sessionFactory, s -> { + // Assert that a left join is used for joining the map key entity table + List keyValues= s.createQuery( "select key(v) from BaseTestEntity bte left join bte.entities te left join te.values v" ).list(); + assertEquals( 2, keyValues.size() ); + } ); + } + @Override protected boolean isCleanupTestDataRequired() { return true; } + @Entity(name = "BaseTestEntity") + @Table(name = "BASE_TEST_ENTITY") + public static class BaseTestEntity { + @Id + @GeneratedValue + Long id; + + @OneToMany + Set entities; + } + @Entity(name = "TestEntity") @Table(name = "TEST_ENTITY") public static class TestEntity {