-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: support for many-to-many on sql-query
PostPosted: Sun Oct 16, 2005 9:07 pm 
Newbie

Joined: Thu Oct 14, 2004 2:48 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.