Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you have to create a <code>BoyGirl</code> class because table <code>BOY_GIRL</code> is not a simple many-to-many table (If it is, then the columns are has to be only <code>boy_id</code> and <code>girl_id</code>). So what you should do is create the <code>BoyGirl</code> class then map <code>BOY</code> to <code>BOY_GIRL</code> with one-to-many and also map <code>GIRL</code> to <code>BOY_GIRL</code> with one-to-many</p> <p><strong>table relations</strong></p> <pre><code>+-------+ +--------------+ +-------+ | BOY | | BOY_GIRL | | GIRL | +-------+ +--------------| +-------+ | id | 0..* --- 1..1 | id | 1..1 --- 0..* | id | | name | | boy_id | | name | | birth | | girl_id | | birth | +-------+ | start_dating | +-------+ +--------------+ </code></pre> <p><strong>java classes</strong></p> <pre><code>public class BoyGirl { private long id; private Boy boy; private Girl girl; private Date startDating; } public class Boy { //other attributes omitted private Set&lt;BoyGirl&gt; boyGirls; } public class Girl { //other attributes omitted private Set&lt;BoyGirl&gt; boyGirls; } </code></pre> <p><strong>The select query you need</strong></p> <pre><code>// I'm using criteria here, but it will have the same result as your HQL public List getGirls(Boy boy, Date startDating) { Criteria c = sessionFactory.getCurrentSession().createCriteria(BoyGirl.class); c.add(Restrictions.eq("boy.id", boy.getId()); c.add(Restrictions.lt("startDating", startDating); List&lt;BoyGirl&gt; boyGirls = (List&lt;BoyGirl&gt;) c.list(); // at this point you have lazily fetch girl attributes // if you need the girl attributes to be initialized uncomment line below // for (BoyGirl boyGirl : boyGirls) Hibernate.initialize(boyGirl.getGirl()); return boyGirls; } </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.
    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.
    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