Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to create an <strong><code>OR</code> expression</strong> with many <a href="http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/Criterion.html" rel="noreferrer"><code>Criterion</code></a> objects, you can use an instance of <a href="http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/Disjunction.html" rel="noreferrer"><code>org.hibernate.criterion.Disjunction</code></a>. Using this object is equivalent to, but more convenient than, using several OR restrictions. To obtain a <code>Disjunction</code> object, call <a href="http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/Restrictions.html#disjunction%28%29" rel="noreferrer"><code>Restrictions.disjunction()</code></a>.</p> <p>If you need to create an <strong><code>AND</code> expression</strong> with many <code>Criterion</code> objects, you can use an object of <a href="http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/Conjunction.html" rel="noreferrer"><code>org.hibernate.criterion.Conjunction</code></a>. The <a href="http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/Restrictions.html#conjunction%28%29" rel="noreferrer"><code>Restrictions.conjunction()</code></a> method returns a <code>Conjunction</code>.</p> <p>The <code>Disjunction</code> and <code>Conjunction</code> classes provide <code>add()</code> methods to apply an OR or an AND, respectively, between the criteria.</p> <h2>Your case:</h2> <p>In your specific case, you can create an outer <code>Disjunction</code> with two <code>Criterion</code>:</p> <ul> <li><code>Student</code>s who do not have a class;</li> <li>a <code>Conjunction</code> with two <code>Criterion</code>: <ul> <li><code>Student</code>s assigned to a <code>classe</code> belonging to the <code>schoolYear</code> <code>"1"</code>;</li> <li><code>Student</code>s that have <code>pass</code> set to <code>true</code>.</li> </ul></li> </ul> <h2>Sample code:</h2> <p>The following code uses both the <code>Disjunction</code> and <code>Conjunction</code> objects to construct the necessary criteria.</p> <pre><code>Criteria c = session.createCriteria(Student.class) .createAlias("assignements", "a") .createAlias("a.classe","c"); Disjunction or = Restrictions.disjunction(); or.add(Restrictions.isNull("classeActuelle")); Conjunction and = Restrictions.conjunction(); and.add(Restrictions.eq("a.pass", Boolean.TRUE) and.add(Restrictions.eq("c.schoolYear", "1")) or.add(and); c.add(or); // you can use your criteria c now </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload