0

请如何在 Hibernate 查询或条件中编写这个简单的工作选择

SELECT * FROM `call` AS c JOIN `event_customer` AS e ON c.customer_id = e.customer_id WHERE e.dgdelete = FALSE AND c.eventruletype_id = 1 AND e.event_id = 74 AND c.callactivity_id = 3 AND e.calltype = 2

我已经找到了很多建议,但没有任何帮助。

它可能与休眠映射有关?

谢谢你。

ps:这个不行

query = session.createQuery("select c from " + Call.class.getSimpleName()+ " as c " + EventCustomer.class.getSimpleName()+ " as e where e.customer_id = c.customer_id and e.event_id = 74"); 

这也不起作用

 query = session.createQuery("select c from " + Call.class.getSimpleName()+ " as c join " + EventCustomer.class.getSimpleName()+ " as e where e.customer_id = c.customer_id and e.event_id = 74");

还有这个

 query = session.createQuery("select c from " + Call.class.getSimpleName()+ " as c join " + EventCustomer.class.getSimpleName()+ " as e on e.customer_id = c.customer_id  where  e.event_id = 74"); 

还有这个

query = session.createQuery("select c from " + Call.class.getSimpleName()+ " as c left join " + EventCustomer.class.getSimpleName()+ " as e on e.customer_id = c.customer_id  where  e.event_id = 74");

在某些情况下,我会收到此错误

4

2 回答 2

2

不要连接,而是使用标准:

Criteria crit = session.createCriteria(Call.class, "c")
    .createCriteria("eventCustomerDto","e")
    .add(Restrictions.eq("event_id",74));
List<Call> list=crit.list();

代码可能有错别字,但就是这样。此外,对于我的示例,我假设 Call 和 EventCustomer 之间的 Call hibernate 映射存在一对多关系。

于 2013-05-07T15:56:13.100 回答
0

这应该有效。(用逗号替换 JOIN)

 Query query = session.createQuery("select c from " + Call.class.getSimpleName() + " as c , " + EventCustomer.class.getSimpleName() + " as e where e.customer.id = c.customer.id and c.event.id = 74");
于 2013-05-09T10:01:26.390 回答