mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-17804 roll back change to semantics of 'null in ()'
It turns out that SQL databases (IMO wrongly) treat the expression 'null in (select 1 where false)' as false instead of null. And as of JPA 3.2, we're free to interpret 'null in ()' consistently with that, which we should do. So my change made things worse rather than better. Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
15cbebbbf9
commit
de3a4c0af9
@ -3206,7 +3206,7 @@ protected String getPrunedDiscriminatorPredicate(
|
||||
Map<String, EntityNameUse> entityNameUses,
|
||||
MappingMetamodelImplementor mappingMetamodel,
|
||||
String alias) {
|
||||
final InFragment frag = new InFragment( false );
|
||||
final InFragment frag = new InFragment();
|
||||
if ( isDiscriminatorFormula() ) {
|
||||
frag.setFormula( alias, getDiscriminatorFormulaTemplate() );
|
||||
}
|
||||
|
@ -21,15 +21,10 @@
|
||||
@Internal
|
||||
public class InFragment {
|
||||
|
||||
public InFragment(boolean columnCanBeNull) {
|
||||
this.columnCanBeNull = columnCanBeNull;
|
||||
}
|
||||
|
||||
public static final String NULL = "null";
|
||||
public static final String NOT_NULL = "not null";
|
||||
|
||||
protected String columnName;
|
||||
protected boolean columnCanBeNull;
|
||||
protected List<Object> values = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@ -71,15 +66,7 @@ public String toFragmentString() {
|
||||
|
||||
switch ( values.size() ) {
|
||||
case 0: {
|
||||
if ( columnCanBeNull ) {
|
||||
return buf.append( "(1 = case when " )
|
||||
.append( columnName )
|
||||
.append(" is not null then 0 end)")
|
||||
.toString();
|
||||
}
|
||||
else {
|
||||
return "0=1";
|
||||
}
|
||||
return "0=1";
|
||||
}
|
||||
case 1: {
|
||||
Object value = values.get( 0 );
|
||||
|
@ -7641,7 +7641,7 @@ public void visitGroupedPredicate(GroupedPredicate groupedPredicate) {
|
||||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
final List<Expression> listExpressions = inListPredicate.getListExpressions();
|
||||
if ( listExpressions.isEmpty() ) {
|
||||
emptyInList( inListPredicate );
|
||||
appendSql( "1=" + ( inListPredicate.isNegated() ? "1" : "0" ) );
|
||||
return;
|
||||
}
|
||||
Function<Expression, Expression> itemAccessor = Function.identity();
|
||||
@ -7748,16 +7748,6 @@ else if ( !supportsRowValueConstructorSyntaxInInList() ) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void emptyInList(InListPredicate inListPredicate) {
|
||||
appendSql("(");
|
||||
appendSql( inListPredicate.isNegated() ? "0" : "1" );
|
||||
appendSql(" = case when ");
|
||||
inListPredicate.getTestExpression().accept( this );
|
||||
appendSql( " is not null then 0");
|
||||
// dialect.appendBooleanValueString( this, inListPredicate.isNegated() );
|
||||
appendSql(" end)");
|
||||
}
|
||||
|
||||
private void appendInClauseSeparator(InListPredicate inListPredicate) {
|
||||
appendSql( CLOSE_PARENTHESIS );
|
||||
appendSql( inListPredicate.isNegated() ? " and " : " or " );
|
||||
|
@ -31,6 +31,7 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@ -334,7 +335,7 @@ public void testEmptyInPredicate2() {
|
||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||
orderCriteria.select( orderRoot );
|
||||
orderCriteria.where( builder.in( orderRoot.get("creditCard") ) );
|
||||
orderCriteria.where( builder.in( orderRoot.get("id") ) );
|
||||
|
||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||
assertTrue( orders.isEmpty() );
|
||||
@ -350,10 +351,10 @@ public void testEmptyInPredicate3() {
|
||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||
orderCriteria.select( orderRoot );
|
||||
orderCriteria.where( builder.in( orderRoot.get("creditCard") ).not() );
|
||||
orderCriteria.where( builder.in( orderRoot.get("id") ).not() );
|
||||
|
||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||
assertTrue( orders.isEmpty() );
|
||||
assertFalse( orders.isEmpty() );
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user