2011-12-13 109 views
2

我有4个表参与此查询。休眠4表的关联

Campaign - 多对一业务

Business - 一对多客户

Client - 一对一接触

Contact 

在接触时,现场contact_name这是独一无二的。我需要检索所有campaigns相关contact(通过clientbusiness),这campaigntype等于2

什么是休眠做到这一点的最好方法是什么?

在SQL是看起来像这样:

select * 
from campaign,contact, business, client 
where campaign.type=2 
and client.contact_id = contact.contact_id 
and contact.name = 'Josh' 
and client.business_id = business.business_id 
and campaign.campaign_id = business.business_id 
+0

找到更多的信息这些表格之间的关系是否已经配置了xml或注解或者是问题的一部分? – flesk

+0

我正在使用注释,并且我确实宣布了一对多对多等,但是,我需要一个有效的解决方案来检索结果 – Dejell

回答

1

我认为以下应工作。

from Compaign where Compaign.type=2 and compaign.business.client.contact.contact_name=:name

+0

它是推荐的方式吗?不通过任何连接? – Dejell

+0

“连接”是什么意思? –

+0

db之间的关系 – Dejell

2

可以执行过使用createSQLQuery()方法本地的SQL查询会议方法。

您还可以使用标量属性来避免使用ResultSetMetadata的开销。
你可以从here