HHH-11877 wrap CompoundPredicate's expression list

This commit is contained in:
Nathan Xu 2020-08-25 10:16:12 -04:00 committed by Christian Beikov
parent e1ff70519a
commit 90be61210c
3 changed files with 79 additions and 1 deletions

View File

@ -80,7 +80,10 @@ public class CompoundPredicate
private void applyExpressions(List<Expression<Boolean>> expressions) { private void applyExpressions(List<Expression<Boolean>> expressions) {
this.expressions.clear(); this.expressions.clear();
this.expressions.addAll( expressions ); final CriteriaBuilderImpl criteriaBuilder = criteriaBuilder();
for ( Expression<Boolean> expression : expressions ) {
this.expressions.add( criteriaBuilder.wrap( expression ) );
}
} }
@Override @Override

View File

@ -0,0 +1,31 @@
package org.hibernate.query.criteria.internal.hhh11877;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Foo {
private long id;
private boolean bar;
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
public long getId() {
return this.id;
}
public void setId(final long id) {
this.id = id;
}
public boolean isBar() {
return this.bar;
}
public void setBar(final boolean bar) {
this.bar = bar;
}
}

View File

@ -0,0 +1,44 @@
package org.hibernate.query.criteria.internal.hhh11877;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
* @author Archie Cobbs
* @author Nathan Xu
*/
@TestForIssue( jiraKey = "HHH-11877" )
public class HHH111877Test extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Foo.class };
}
@Test
public void testNoExceptionThrow() {
doInJPA( this::entityManagerFactory, entityManager -> {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Foo> cq = cb.createQuery( Foo.class );
final Root<Foo> foo = cq.from( Foo.class );
cq.select( foo ).where( cb.and( cb.and(), foo.get( Foo_.bar ) ) );
final TypedQuery<Foo> tq = entityManager.createQuery( cq );
// without fixing, the statement below will throw exception:
// java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: . near line 1, column 106 [select generatedAlias0 from org.hibernate.bugs.Foo as generatedAlias0 where ( 1=1 ) and ( generatedAlias0.bar )]
tq.getResultList();
} );
}
}