HHH-17492 Add test for issue

This commit is contained in:
Marco Belladelli 2023-12-06 12:25:08 +01:00 committed by Christian Beikov
parent 7703648f1e
commit 9c18319c1c
1 changed files with 42 additions and 4 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.query.hql;
import java.math.BigInteger;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
@ -14,27 +15,30 @@ import java.util.List;
import org.hibernate.boot.MetadataSources;
import org.hibernate.query.Query;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.domain.contacts.Contact;
import org.hibernate.testing.orm.domain.contacts.ContactsDomainModel;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
import org.hibernate.testing.orm.junit.Jira;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-10893")
public class MultiValuedParameterTest extends BaseSessionFactoryFunctionalTest {
@Override
protected void applyMetadataSources(MetadataSources metadataSources) {
super.applyMetadataSources( metadataSources );
ContactsDomainModel.applyContactsModel( metadataSources );
metadataSources.addAnnotatedClass( EntityWithNumericId.class );
}
@BeforeAll
@ -48,13 +52,17 @@ public class MultiValuedParameterTest extends BaseSessionFactoryFunctionalTest {
Contact.Gender.MALE,
LocalDate.now()
);
session.save( p1 );
session.persist( p1 );
if ( i < 3 ) {
session.persist( new EntityWithNumericId( BigInteger.valueOf( i ) ) );
}
}
}
);
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-10893" )
public void testParameterListIn() {
inTransaction(
session -> {
@ -80,8 +88,38 @@ public class MultiValuedParameterTest extends BaseSessionFactoryFunctionalTest {
);
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17492" )
public void test() {
inTransaction( session -> {
final List<BigInteger> ids = List.of( BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO );
final List<EntityWithNumericId> resultList = session.createQuery(
"select id from EntityWithNumericId e WHERE e.id in (:ids)",
EntityWithNumericId.class
).setParameter( "ids", ids ).getResultList();
assertThat( resultList.size(), is( 3 ) );
assertThat( resultList, is( ids ) );
} );
}
@AfterAll
public void cleanupData() {
inTransaction( session -> session.createQuery( "delete Contact" ).executeUpdate() );
inTransaction( session -> {
session.createMutationQuery( "delete Contact" ).executeUpdate();
session.createMutationQuery( "delete EntityWithNumericId" ).executeUpdate();
} );
}
@Entity( name = "EntityWithNumericId" )
public static class EntityWithNumericId {
@Id
private BigInteger id;
public EntityWithNumericId() {
}
public EntityWithNumericId(BigInteger id) {
this.id = id;
}
}
}