Test for HHH-10537

This commit is contained in:
Christian Beikov 2017-01-25 19:58:34 +01:00 committed by Chris Cranford
parent fa3171530c
commit 72382b1e08
1 changed files with 31 additions and 0 deletions

View File

@ -11,11 +11,14 @@ import javax.persistence.Embeddable;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.query.Query; import org.hibernate.query.Query;
@ -43,6 +46,7 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class[] { return new Class[] {
BaseTestEntity.class,
TestEntity.class, TestEntity.class,
KeyValue.class KeyValue.class
}; };
@ -53,14 +57,20 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC
doInHibernate( this::sessionFactory, s -> { doInHibernate( this::sessionFactory, s -> {
s.save( keyValue ); s.save( keyValue );
BaseTestEntity baseTestEntity1 = new BaseTestEntity();
TestEntity testEntity = new TestEntity(); TestEntity testEntity = new TestEntity();
Map<KeyValue, EmbeddableValue> map = new HashMap<>(); Map<KeyValue, EmbeddableValue> map = new HashMap<>();
map.put( keyValue, embeddableValue ); map.put( keyValue, embeddableValue );
testEntity.values = map; testEntity.values = map;
s.save( testEntity ); s.save( testEntity );
baseTestEntity1.entities = new HashSet<TestEntity>();
baseTestEntity1.entities.add( testEntity );
s.save( baseTestEntity1 );
KeyValue keyValue2 = new KeyValue( "key2" ); KeyValue keyValue2 = new KeyValue( "key2" );
s.save( keyValue2 ); s.save( keyValue2 );
BaseTestEntity baseTestEntity2 = new BaseTestEntity();
s.save( baseTestEntity2 );
TestEntity testEntity2 = new TestEntity(); TestEntity testEntity2 = new TestEntity();
Map<KeyValue, EmbeddableValue> map2 = new HashMap<>(); Map<KeyValue, EmbeddableValue> map2 = new HashMap<>();
map.put( keyValue2, embeddableValue ); map.put( keyValue2, embeddableValue );
@ -176,11 +186,32 @@ public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestC
} ); } );
} }
@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 @Override
protected boolean isCleanupTestDataRequired() { protected boolean isCleanupTestDataRequired() {
return true; return true;
} }
@Entity(name = "BaseTestEntity")
@Table(name = "BASE_TEST_ENTITY")
public static class BaseTestEntity {
@Id
@GeneratedValue
Long id;
@OneToMany
Set<TestEntity> entities;
}
@Entity(name = "TestEntity") @Entity(name = "TestEntity")
@Table(name = "TEST_ENTITY") @Table(name = "TEST_ENTITY")
public static class TestEntity { public static class TestEntity {