Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate HQL m:n join problem
    primarykey
    data
    text
    <p>I am very unfamiliar with SQL/HQL , and am currently stuck with this 'maybe' simple problem :</p> <p>I have two many-to-many Entities , with a relation table :</p> <p>Car , CarProblem , and Problem .</p> <p>One Car may have many Problems , </p> <p>One Problem may appear in many Cars,</p> <p>CarProblem is the association table with other properties .</p> <p>Now , I want to find Car(s) with specified Problem , how do I write such HQL ? All ids are Long type .</p> <p>I've tried a lot of join / inner-join combinations , but all in vain..</p> <p>-- updated :</p> <p>Sorry , forget to mention :</p> <p>Car has many CarProblem</p> <p>Problem has many CarProblem</p> <p>Car and Problem are not directly connected in Java Object.</p> <p>-- update , java code below --</p> <pre><code>@Entity public class Car extends Model{ @OneToMany(mappedBy="car" , cascade=CascadeType.ALL) public Set&lt;CarProblem&gt; carProblems; } @Entity public class CarProblem extends Model{ @ManyToOne public Car car; @ManyToOne public Problem problem; ... other properties } @Entity public class Problem extends Model { other properties ... // not link to CarProblem , It seems not related to this problem // **This is a very stupid query , I want to get rid of it ...** public List&lt;Car&gt; findCars() { List&lt;CarProblem&gt; list = CarProblem.find("from CarProblem as cp where cp.problem.id = ? ", id).fetch(); Set&lt;Car&gt; result = new HashSet&lt;Car&gt;(); for(CarProblem cp : list) result.add(cp.car); return new ArrayList&lt;Car&gt;(result); } } </code></pre> <p>The Model is from Play! framework , so these properties are all public .</p>
    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. 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