mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-12 22:24:47 +00:00
HHH-17490 Fix not in and empty list parameter predicate
This commit is contained in:
parent
cfe41ed8bb
commit
8e5f847201
@ -201,7 +201,7 @@ else if ( expression instanceof Summarization ) {
|
||||
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 @@ else if ( expression instanceof Summarization ) {
|
||||
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();
|
||||
|
@ -199,7 +199,7 @@ else if ( expression instanceof Summarization ) {
|
||||
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();
|
||||
|
@ -6957,7 +6957,7 @@ public void visitGroupedPredicate(GroupedPredicate groupedPredicate) {
|
||||
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.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.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 void testParameterListInExistingParens() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
@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…
x
Reference in New Issue
Block a user