diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TupleQueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TupleQueryTest.java index ccb13e29c504..810523e7bab8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TupleQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/TupleQueryTest.java @@ -16,15 +16,21 @@ import java.util.List; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Andrea Boriero @@ -85,6 +91,23 @@ public void testGetAlias(EntityManagerFactoryScope scope) { ); } + @Test + @JiraKey( "HHH-16742" ) + public void testTwoDifferentAliasesToSameColumn(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + TypedQuery query = entityManager.createQuery( "SELECT u.firstName as fn, u.firstName as fn_2 from User u", Tuple.class ); + + Tuple result = query.getResultList().get(0); + assertNotNull( result ); + assertEquals( 2, result.getElements().size() ); + // Should not throw IllegalArgumentException + result.get("fn", String.class); + result.get("fn_2", String.class); + } + ); + } + @Entity(name = "User") @Table(name = "USERS") public static class User {