Throw IllegalArgumentException for null Criteria literal value
This commit is contained in:
parent
fb17eb52df
commit
9fba739bc2
|
@ -914,6 +914,9 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
|
||||||
@Override
|
@Override
|
||||||
public <T> SqmLiteral<T> literal(T value) {
|
public <T> SqmLiteral<T> literal(T value) {
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
|
if ( jpaComplianceEnabled ) {
|
||||||
|
throw new IllegalArgumentException( "literal value cannot be null" );
|
||||||
|
}
|
||||||
return new SqmLiteralNull<>( this );
|
return new SqmLiteralNull<>( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.hibernate.orm.test.jpa.compliance;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
|
import org.hibernate.testing.orm.junit.Setting;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
@Jpa(
|
||||||
|
properties = @Setting(name = AvailableSettings.JPA_QUERY_COMPLIANCE, value = "true")
|
||||||
|
)
|
||||||
|
public class CriteriaLiteralValue {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLiteralValueCannotBeNull(EntityManagerFactoryScope scope) {
|
||||||
|
|
||||||
|
final CriteriaBuilder builder = scope.getEntityManagerFactory().getCriteriaBuilder();
|
||||||
|
try {
|
||||||
|
builder.literal(null);
|
||||||
|
fail( "TCK expects an IllegalArgumentException" );
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
// //expected by TCK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue