Note that there are some explanatory texts on larger screens.

plurals
  1. PO@OneToMany shows duplicate values for collection variable
    primarykey
    data
    text
    <p>I am getting filtered 'Trainer' entities, but collection (trainedMonkeys) is not filtered. 'trainedMonkeys' variable is holding all 'Monkey' objects instead of holding only the one with 'isThumb = true'.</p> <p>Can someone please check if below criteria I am using is correct?</p> <pre><code>@SuppressWarnings("unchecked") public List&amp;lt;Trainer&amp;gt; listTrainers() { Criteria crit = sessionFactory.getCurrentSession().createCriteria(Trainer.class) .createAlias("trainedMonkeys", "tm") .add(Restrictions.eq("tm.isThumb", true)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); </code></pre> <p>Trainer.java</p> <pre><code>public class Trainer { private Long trainerId; private String trainerName; public List&amp;lt;Monkey&amp;gt; trainedMonkeys; </code></pre> <p>Monkey.java</p> <pre><code>public class Monkey { private Long id; private String monkeyName; private boolean isThumb; </code></pre> <p>I am executing below code in the controller,</p> <pre><code>for (Trainer trainer : trainerList){ System.err.println("&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"); System.err.println("Trainer ID*****"+trainer.getTrainerId()); System.err.println("Trainer Name******"+trainer.getTrainerName()); monkeyList = trainer.getTrainedMonkeys(); for (Monkey monkey : monkeyList){ System.err.println("Monkey ID*****"+monkey.getId()); System.err.println("Monkey Name*****"+monkey.getMonkeyName()); } System.err.println("&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;"); } </code></pre> <p>and the output is as below (Monkey_2 and Monkey_6 are the only objects that should be present as only they satisfy the criteria) please help,</p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Trainer ID*****88 Trainer Name******TrainerSachin Monkey ID*****87 Monkey Name*****Monkey_1 Monkey ID*****88 Monkey Name*****Monkey_2 Monkey ID*****89 Monkey Name*****Monkey_3 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Trainer ID*****89 Trainer Name******TrainerVinod Monkey ID*****90 Monkey Name*****Monkey_5 Monkey ID*****91 Monkey Name*****Monkey_6 Monkey ID*****92 Monkey Name*****Monkey_7 &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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