Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
 3.0.5
Mapping documents:
<class table="tb_employee" name="model.Employee">
  ...
  <loader query-ref="sql_employee"/>
</class>
 <sql-query name="sql_employee">
    <return alias="E" class="model.Employee"/>
    <return-join alias="a" property="E.address"/>
    <return-join alias="b" property="E.bonus"/>
    <return-join alias="emp_proj" property="E.projects" />
    <![CDATA[
  select {E.*} , {a.*} ,  {b.*},  {emp_proj.*}
  from tb_employee E 
  left outer join tb_address a on f.id_address = a.id_address
  left outer join tb_bonus b on b.id_employee = f.id_employee
  left outer join tb_emp_proj emp_proj 
                                    on f.id_employee = emp_proj.id_employee		
  where E.id_employee = :id
    ]]>
</sql-query>
Code between sessionFactory.openSession() and session.close():
Empoyee e = (Employee) session.get(Employee.class, new Integer(12));
Name and version of the database you are using:
MySQL 4
Employee has a many-to-many association to Project.
The best I can do on the sql-query above is the one-to-many join on intermediate table (tb_emp_proj). This works but fetches projects by additional selects...
I would like to fetch the employee projects collection trought a join (on tb_project). I tried like this...
 <sql-query name="sql_employee">
    <return alias="E" class="model.Employee"/>
    ...
    <return-join alias="proj" property="E.projects" />
    <![CDATA[
  select {E.*} , {a.*} ,  {b.*},  {proj.*}
  from tb_employee E 
  ...
  left outer join tb_emp_proj emp_proj 
                                    on f.id_employee = emp_proj.id_employee		
  left outer join tb_project proj on emp_proj.id_project = proj.id_project
  where E.id_employee = :id
    ]]>
</sql-query>
But the generated query assumes the intermeditate table role for tb_project:
select ..., proj.id_employee as id1_1__, proj.id_projecto as id2_1__
Is there this kind of support ?
Tks