diff --git a/hibernate-core/src/main/java/org/hibernate/criterion/Restrictions.java b/hibernate-core/src/main/java/org/hibernate/criterion/Restrictions.java index 6530588357..bdad9f5741 100755 --- a/hibernate-core/src/main/java/org/hibernate/criterion/Restrictions.java +++ b/hibernate-core/src/main/java/org/hibernate/criterion/Restrictions.java @@ -242,6 +242,22 @@ public class Restrictions { public static LogicalExpression and(Criterion lhs, Criterion rhs) { return new LogicalExpression(lhs, rhs, "and"); } + /** + * Return the conjuction of multiple expressions + * + * @param predicates The predicates making up the initial junction + * + * @return The conjunction + */ + public static Conjunction and(Criterion... predicates) { + Conjunction conjunction = conjunction(); + if ( predicates != null ) { + for ( Criterion predicate : predicates ) { + conjunction.add( predicate ); + } + } + return conjunction; + } /** * Return the disjuction of two expressions * @@ -252,6 +268,22 @@ public class Restrictions { public static LogicalExpression or(Criterion lhs, Criterion rhs) { return new LogicalExpression(lhs, rhs, "or"); } + /** + * Return the disjuction of multiple expressions + * + * @param predicates The predicates making up the initial junction + * + * @return The conjunction + */ + public static Disjunction or(Criterion... predicates) { + Disjunction disjunction = disjunction(); + if ( predicates != null ) { + for ( Criterion predicate : predicates ) { + disjunction.add( predicate ); + } + } + return disjunction; + } /** * Return the negation of an expression * diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/criteria/CriteriaQueryTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/criteria/CriteriaQueryTest.java index 24779bb352..8cf7aba98e 100755 --- a/hibernate-core/src/matrix/java/org/hibernate/test/criteria/CriteriaQueryTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/criteria/CriteriaQueryTest.java @@ -95,6 +95,37 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase { cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); } + @Test + @TestForIssue( jiraKey = "HHH-7209" ) + public void testVarargJunctionSyntax() { + Session session = openSession(); + session.beginTransaction(); + session.createCriteria( Course.class ) + .add( + Restrictions.and( + Property.forName( "description" ).like( "Hibernate%" ), + Property.forName( "description" ).like( "%ORM%" ) + ) + ) + .list(); + + session.createCriteria( Course.class ) + .add( + Restrictions.and( + Property.forName( "description" ).like( "Hibernate%" ), + Restrictions.or( + Property.forName( "description" ).like( "%ORM%" ), + Property.forName( "description" ).like( "%Search%" ) + ) + + ) + ) + .list(); + + session.getTransaction().commit(); + session.close(); + } + @Test public void testEscapeCharacter() { Session session = openSession();