HHH-17803 Add test for issue

This commit is contained in:
Marco Belladelli 2024-03-05 10:59:47 +01:00
parent d9c57c6a70
commit 6c172c3a22
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
1 changed files with 29 additions and 2 deletions

View File

@ -19,6 +19,8 @@ import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Convert; import jakarta.persistence.Convert;
import jakarta.persistence.Converter; import jakarta.persistence.Converter;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -33,12 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat;
@SessionFactory @SessionFactory
@Jira( "https://hibernate.atlassian.net/browse/HHH-17332" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-17332" )
@Jira( "https://hibernate.atlassian.net/browse/HHH-17701" ) @Jira( "https://hibernate.atlassian.net/browse/HHH-17701" )
@Jira( "https://hibernate.atlassian.net/browse/HHH-17803" )
public class InSubqueryPredicateAnonymousTupleTest { public class InSubqueryPredicateAnonymousTupleTest {
@BeforeAll @BeforeAll
public void setUp(SessionFactoryScope scope) { public void setUp(SessionFactoryScope scope) {
scope.inTransaction( session -> { scope.inTransaction( session -> {
session.persist( new BasicEntity( 1, "test" ) ); session.persist( new BasicEntity( 1, "test" ) );
session.persist( new TestEntity( 1L, new Money( 100L ) ) ); session.persist( new TestEntity( 1L, new Money( 100L ), Status.VALID ) );
} ); } );
} }
@ -84,6 +87,18 @@ public class InSubqueryPredicateAnonymousTupleTest {
} ); } );
} }
@Test
public void testEnumeratedAttributeTuple(SessionFactoryScope scope) {
scope.inTransaction( session -> {
final TestEntity result = session.createQuery(
"select t from TestEntity t where (t.id, t.status) in " +
"(select t2.id, t2.status from TestEntity t2)",
TestEntity.class
).getSingleResult();
assertThat( result.getStatus() ).isEqualTo( Status.VALID );
} );
}
@Entity( name = "TestEntity" ) @Entity( name = "TestEntity" )
public static class TestEntity { public static class TestEntity {
@Id @Id
@ -92,17 +107,29 @@ public class InSubqueryPredicateAnonymousTupleTest {
@Convert( converter = MoneyConverter.class ) @Convert( converter = MoneyConverter.class )
private Money money; private Money money;
@Enumerated( EnumType.STRING )
private Status status;
public TestEntity() { public TestEntity() {
} }
public TestEntity(Long id, Money money) { public TestEntity(Long id, Money money, Status status) {
this.id = id; this.id = id;
this.money = money; this.money = money;
this.status = status;
} }
public Money getMoney() { public Money getMoney() {
return money; return money;
} }
public Status getStatus() {
return status;
}
}
public enum Status {
VALID, INVALID
} }
public static class Money { public static class Money {