Skip to content

Commit

Permalink
Test for HHH-10577
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov authored and Naros committed Feb 1, 2017
1 parent d48f393 commit f9fce8c
Showing 1 changed file with 24 additions and 6 deletions.
Expand Up @@ -6,10 +6,6 @@
*/
package org.hibernate.test.hql;

/**
* @author Andrea Boriero
*/

import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
Expand All @@ -24,6 +20,7 @@
import org.hibernate.query.Query;
import org.hibernate.resource.transaction.spi.TransactionStatus;

import org.hibernate.testing.TestForIssue;
import org.junit.After;
import org.junit.Test;

Expand All @@ -37,9 +34,10 @@

/**
* @author Andrea Boriero
* @author Christian Beikov
*/
public class CollectionMapWithComponentValueTest extends BaseCoreFunctionalTestCase {
private final KeyValue keyValue = new KeyValue();
private final KeyValue keyValue = new KeyValue( "key1" );

@Override
protected Class<?>[] getAnnotatedClasses() {
Expand All @@ -62,7 +60,7 @@ protected void prepareTest() throws Exception {
testEntity.values = map;
s.save( testEntity );

KeyValue keyValue2 = new KeyValue();
KeyValue keyValue2 = new KeyValue( "key2" );
s.save( keyValue2 );
TestEntity testEntity2 = new TestEntity();
EmbeddableValue embeddableValue2 = new EmbeddableValue();
Expand Down Expand Up @@ -133,6 +131,17 @@ public void testMapEntryExpressionInSelect() {
} );
}

@Test
@TestForIssue(jiraKey = "HHH-10577")
public void testMapKeyExpressionDereferenceInSelect() {
doInHibernate( this::sessionFactory, s -> {
List<String> keyValueNames = s.createQuery( "select key(v).name as name from TestEntity te join te.values v order by name", String.class ).list();
assertEquals( 2, keyValueNames.size() );
assertEquals( "key1", keyValueNames.get( 0 ) );
assertEquals( "key2", keyValueNames.get( 1 ) );
} );
}

@Override
protected boolean isCleanupTestDataRequired() {
return true;
Expand All @@ -155,6 +164,15 @@ public static class KeyValue {
@Id
@GeneratedValue
Long id;

String name;

public KeyValue() {
}

public KeyValue(String name) {
this.name = name;
}
}

@Embeddable
Expand Down

0 comments on commit f9fce8c

Please sign in to comment.