HHH-16305 Add test for issue
This commit is contained in:
parent
aafb7cdd45
commit
4543113e68
|
@ -6,61 +6,70 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.query;
|
package org.hibernate.orm.test.query;
|
||||||
|
|
||||||
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.JiraKey;
|
import org.hibernate.testing.orm.junit.Jira;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import jakarta.persistence.Tuple;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Marco Belladelli
|
* @author Marco Belladelli
|
||||||
*/
|
*/
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
@DomainModel(annotatedClasses = BasicEntity.class)
|
@DomainModel( annotatedClasses = EntityOfBasics.class )
|
||||||
@JiraKey("HHH-16137")
|
|
||||||
public class NamedParameterInSelectAndWhereTest {
|
public class NamedParameterInSelectAndWhereTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public void setUp(SessionFactoryScope scope) {
|
public void setUp(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
BasicEntity be1 = new BasicEntity( 1, "one" );
|
final EntityOfBasics e1 = new EntityOfBasics( 1 );
|
||||||
session.persist( be1 );
|
final EntityOfBasics e2 = new EntityOfBasics( 2 );
|
||||||
BasicEntity be2 = new BasicEntity( 2, "two" );
|
e2.setTheLocalDate( LocalDate.EPOCH );
|
||||||
session.persist( be2 );
|
session.persist( e1 );
|
||||||
|
session.persist( e2 );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public void tearDown(SessionFactoryScope scope) {
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> session.createMutationQuery( "delete from BasicEntity" ).executeUpdate() );
|
scope.inTransaction( session -> session.createMutationQuery( "delete from EntityOfBasics" ).executeUpdate() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16137" )
|
||||||
public void testSelectAndWhere(SessionFactoryScope scope) {
|
public void testSelectAndWhere(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> assertEquals(
|
scope.inTransaction( session -> assertEquals( 1, session.createQuery(
|
||||||
1,
|
"select :param from EntityOfBasics e where e.id > :param",
|
||||||
session.createQuery( "SELECT :param FROM BasicEntity be WHERE be.id > :param", Integer.class )
|
|
||||||
.setParameter( "param", 1 )
|
|
||||||
.getSingleResult()
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSelectAndWhereIsNull(SessionFactoryScope scope) {
|
|
||||||
scope.inTransaction( session -> assertEquals(
|
|
||||||
1,
|
|
||||||
session.createQuery(
|
|
||||||
"SELECT :param FROM BasicEntity be WHERE :param is null or be.id > :param",
|
|
||||||
Integer.class
|
Integer.class
|
||||||
)
|
)
|
||||||
.setParameter( "param", 1 )
|
.setParameter( "param", 1 )
|
||||||
.getSingleResult()
|
.getSingleResult() ) );
|
||||||
) );
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16137" )
|
||||||
|
public void testSelectAndWhereIsNull(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> assertEquals( 1, session.createQuery(
|
||||||
|
"select :param from EntityOfBasics be where :param is null or be.id > :param",
|
||||||
|
Integer.class
|
||||||
|
).setParameter( "param", 1 )
|
||||||
|
.getSingleResult() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-16305" )
|
||||||
|
public void testSelectFunctionAndWhere(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> assertEquals( 0, session.createQuery(
|
||||||
|
"select timestampdiff(year, e.theLocalDate, :date) from EntityOfBasics e where e.theLocalDate <= :date",
|
||||||
|
Long.class
|
||||||
|
)
|
||||||
|
.setParameter( "date", LocalDate.EPOCH )
|
||||||
|
.getSingleResult() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue