HHH-17490 Fix not in and empty list parameter predicate
This commit is contained in:
parent
f4f62c81fa
commit
7c58fe9a16
|
@ -269,7 +269,7 @@ public class DerbyLegacySqlAstTranslator<T extends JdbcOperation> extends Abstra
|
|||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
final List<Expression> listExpressions = inListPredicate.getListExpressions();
|
||||
if ( listExpressions.isEmpty() ) {
|
||||
appendSql( "1=0" );
|
||||
appendSql( "1=" + ( inListPredicate.isNegated() ? "1" : "0" ) );
|
||||
return;
|
||||
}
|
||||
final Expression testExpression = inListPredicate.getTestExpression();
|
||||
|
|
|
@ -229,7 +229,7 @@ public class FirebirdSqlAstTranslator<T extends JdbcOperation> extends AbstractS
|
|||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
final List<Expression> listExpressions = inListPredicate.getListExpressions();
|
||||
if ( listExpressions.isEmpty() ) {
|
||||
appendSql( "1=0" );
|
||||
appendSql( "1=" + ( inListPredicate.isNegated() ? "1" : "0" ) );
|
||||
return;
|
||||
}
|
||||
final Expression testExpression = inListPredicate.getTestExpression();
|
||||
|
|
|
@ -269,7 +269,7 @@ public class DerbySqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
|
|||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
final List<Expression> listExpressions = inListPredicate.getListExpressions();
|
||||
if ( listExpressions.isEmpty() ) {
|
||||
appendSql( "1=0" );
|
||||
appendSql( "1=" + ( inListPredicate.isNegated() ? "1" : "0" ) );
|
||||
return;
|
||||
}
|
||||
final Expression testExpression = inListPredicate.getTestExpression();
|
||||
|
|
|
@ -7555,7 +7555,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
|||
public void visitInListPredicate(InListPredicate inListPredicate) {
|
||||
final List<Expression> listExpressions = inListPredicate.getListExpressions();
|
||||
if ( listExpressions.isEmpty() ) {
|
||||
appendSql( "1=0" );
|
||||
appendSql( "1=" + ( inListPredicate.isNegated() ? "1" : "0" ) );
|
||||
return;
|
||||
}
|
||||
Function<Expression, Expression> itemAccessor = Function.identity();
|
||||
|
|
|
@ -22,6 +22,7 @@ import jakarta.persistence.PersistenceException;
|
|||
import jakarta.persistence.Query;
|
||||
import jakarta.persistence.TemporalType;
|
||||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.QueryException;
|
||||
|
@ -38,6 +39,7 @@ import org.hibernate.stat.Statistics;
|
|||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.Jira;
|
||||
import org.junit.Test;
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
@ -894,6 +896,54 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Jira( "https://hibernate.atlassian.net/browse/HHH-17490" )
|
||||
public void testEmptyParameterList() throws Exception {
|
||||
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||
final Item item2 = new Item( "Computer", "Dell computer" );
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
try {
|
||||
em.persist( item );
|
||||
em.persist( item2 );
|
||||
assertTrue( em.contains( item ) );
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.getTransaction().begin();
|
||||
TypedQuery<Item> q = em.createQuery(
|
||||
"select item from Item item where item.name in :names",
|
||||
Item.class
|
||||
);
|
||||
q.setParameter( "names", List.of() );
|
||||
List<Item> result = q.getResultList();
|
||||
assertNotNull( result );
|
||||
assertEquals( 0, result.size() );
|
||||
|
||||
q = em.createQuery(
|
||||
"select item from Item item where item.name not in :names",
|
||||
Item.class
|
||||
);
|
||||
q.setParameter( "names", List.of() );
|
||||
result = q.getResultList();
|
||||
assertNotNull( result );
|
||||
assertEquals( 2, result.size() );
|
||||
|
||||
em.remove( result.get( 0 ) );
|
||||
em.remove( result.get( 1 ) );
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e){
|
||||
if ( em.getTransaction() != null && em.getTransaction().isActive() ) {
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeCharacter() throws Exception {
|
||||
final Item item = new Item( "Mouse", "Micro_oft mouse" );
|
||||
|
|
Loading…
Reference in New Issue