re-enable tests
re-organize some tests CastNullSelectExpressionTest (not-implemented-yet)
This commit is contained in:
parent
4917d7c6bd
commit
b31f2c02d7
|
@ -2287,7 +2287,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
||||||
return new NullnessLiteral( mappingModelExpressable );
|
return new NullnessLiteral( mappingModelExpressable );
|
||||||
}
|
}
|
||||||
final MappingModelExpressable keyExpressable = getKeyExpressable( mappingModelExpressable );
|
final MappingModelExpressable keyExpressable = getKeyExpressable( mappingModelExpressable );
|
||||||
|
if ( keyExpressable == null ) {
|
||||||
|
throw new IllegalArgumentException( "Could not determine type for null literal" );
|
||||||
|
}
|
||||||
|
|
||||||
final List<Expression> expressions = new ArrayList<>( keyExpressable.getJdbcTypeCount() );
|
final List<Expression> expressions = new ArrayList<>( keyExpressable.getJdbcTypeCount() );
|
||||||
|
|
||||||
keyExpressable.forEachJdbcType(
|
keyExpressable.forEachJdbcType(
|
||||||
(index, jdbcMapping) -> expressions.add(
|
(index, jdbcMapping) -> expressions.add(
|
||||||
new QueryLiteral<>(
|
new QueryLiteral<>(
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*/
|
||||||
|
package org.hibernate.orm.test.query.hql;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gail Badner
|
||||||
|
*/
|
||||||
|
@DomainModel( annotatedClasses = CastNullSelectExpressionTest.Person.class )
|
||||||
|
@SessionFactory
|
||||||
|
@NotImplementedYet( reason = "Combination of https://github.com/hibernate/hibernate-orm/discussions/3921 and https://github.com/hibernate/hibernate-orm/discussions/3889" )
|
||||||
|
public class CastNullSelectExpressionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-10757")
|
||||||
|
public void testSelectCastNull(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
(session) -> {
|
||||||
|
Object[] result = (Object[]) session.createQuery(
|
||||||
|
"select firstName, cast( null as string ), lastName from CastNullSelectExpressionTest$Person where lastName='Munster'"
|
||||||
|
).uniqueResult();
|
||||||
|
|
||||||
|
assertEquals( 3, result.length );
|
||||||
|
assertEquals( "Herman", result[0] );
|
||||||
|
assertNull( result[1] );
|
||||||
|
assertEquals( "Munster", result[2] );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-10757")
|
||||||
|
public void testSelectNewCastNull(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
(session) -> {
|
||||||
|
Person result = (Person) session.createQuery(
|
||||||
|
"select new CastNullSelectExpressionTest$Person( id, firstName, cast( null as string ), lastName ) from CastNullSelectExpressionTest$Person where lastName='Munster'"
|
||||||
|
).uniqueResult();
|
||||||
|
assertEquals( "Herman", result.firstName );
|
||||||
|
assertNull( result.middleName );
|
||||||
|
assertEquals( "Munster", result.lastName );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void createTestData(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
(session) -> {
|
||||||
|
Person person = new Person();
|
||||||
|
person.firstName = "Herman";
|
||||||
|
person.middleName = "Joseph";
|
||||||
|
person.lastName = "Munster";
|
||||||
|
session.persist( person );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void dropTestData(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
(session) -> session.createQuery( "delete Person" ).executeUpdate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "PERSON")
|
||||||
|
public static class Person {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
private String middleName;
|
||||||
|
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
private Integer age;
|
||||||
|
|
||||||
|
Person() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person(long id, String firstName, String middleName, String lastName) {
|
||||||
|
this.id = id;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.middleName = middleName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person(long id, String firstName, Integer age, String lastName) {
|
||||||
|
this.id = id;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.middleName = null;
|
||||||
|
this.lastName = lastName;
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,118 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.hql;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Gail Badner
|
|
||||||
*/
|
|
||||||
@TestForIssue( jiraKey = "HHH-10757")
|
|
||||||
public class CastNullSelectExpressionTest extends BaseCoreFunctionalTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-10757")
|
|
||||||
public void testSelectCastNull() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
Person person = new Person();
|
|
||||||
person.firstName = "Herman";
|
|
||||||
person.middleName = "Joseph";
|
|
||||||
person.lastName = "Munster";
|
|
||||||
s.persist( person );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
Object[] result = (Object[]) s.createQuery(
|
|
||||||
"select firstName, cast( null as string ), lastName from CastNullSelectExpressionTest$Person where lastName='Munster'"
|
|
||||||
).uniqueResult();
|
|
||||||
|
|
||||||
assertEquals( 3, result.length );
|
|
||||||
assertEquals( "Herman", result[0] );
|
|
||||||
assertNull( result[1] );
|
|
||||||
assertEquals( "Munster", result[2] );
|
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@TestForIssue(jiraKey = "HHH-10757")
|
|
||||||
public void testSelectNewCastNull() {
|
|
||||||
Session s = openSession();
|
|
||||||
s.getTransaction().begin();
|
|
||||||
Person person = new Person();
|
|
||||||
person.firstName = "Herman";
|
|
||||||
person.middleName = "Joseph";
|
|
||||||
person.lastName = "Munster";
|
|
||||||
s.persist( person );
|
|
||||||
s.flush();
|
|
||||||
s.clear();
|
|
||||||
|
|
||||||
Person result = (Person) s.createQuery(
|
|
||||||
"select new CastNullSelectExpressionTest$Person( id, firstName, cast( null as string ), lastName ) from CastNullSelectExpressionTest$Person where lastName='Munster'"
|
|
||||||
).uniqueResult();
|
|
||||||
assertEquals( "Herman", result.firstName );
|
|
||||||
assertNull( result.middleName );
|
|
||||||
assertEquals( "Munster", result.lastName );
|
|
||||||
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class[] { Person.class };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "PERSON")
|
|
||||||
private static class Person {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
private String firstName;
|
|
||||||
|
|
||||||
private String middleName;
|
|
||||||
|
|
||||||
private String lastName;
|
|
||||||
|
|
||||||
private Integer age;
|
|
||||||
|
|
||||||
Person() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Person(long id, String firstName, String middleName, String lastName) {
|
|
||||||
this.id = id;
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.middleName = middleName;
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Person(long id, String firstName, Integer age, String lastName) {
|
|
||||||
this.id = id;
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.middleName = null;
|
|
||||||
this.lastName = lastName;
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -54,7 +54,8 @@ public class NotImplementedYetExtension
|
||||||
return ConditionEvaluationResult.enabled( "@NotImplementedYet validation" );
|
return ConditionEvaluationResult.enabled( "@NotImplementedYet validation" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ConditionEvaluationResult.disabled( "Disabled : @NotImplementedYet" );
|
final Optional<NotImplementedYet> annotation = TestingUtil.findEffectiveAnnotation( context, NotImplementedYet.class );
|
||||||
|
return ConditionEvaluationResult.disabled( "Disabled : @NotImplementedYet - " + annotation.get().reason() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ConditionEvaluationResult.enabled( "No @NotImplementedYet" );
|
return ConditionEvaluationResult.enabled( "No @NotImplementedYet" );
|
||||||
|
|
Loading…
Reference in New Issue