Hibernate 标准:在没有映射关联的情况下连接表 [英] Hibernate criteria: Joining table without a mapped association

查看:40
本文介绍了Hibernate 标准:在没有映射关联的情况下连接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Hibernate 的标准 API 来制定连接两个实体的特定查询.假设我有两个实体,Pet 和 Owner,其中一个所有者拥有许多宠物,但至关重要的是,该关联并未映射到 Java 注释或 xml 中.

I'd like to use Hibernate's criteria api to formulate a particular query that joins two entities. Let's say I have two entities, Pet and Owner with a owner having many pets, but crucially that association is not mapped in the Java annotations or xml.

使用 hql,我可以通过在查询中指定联接(而不是将一组宠物添加到所有者类)来选择拥有名为fido"的宠物的所有者.

With hql, I could select owners that have a pet called 'fido' by specifying the join in the query (rather than adding a set of pets to the owner class).

是否可以使用休眠条件来完成相同的操作?如果是这样怎么办?

Can the same be done using hibernate criteria? If so how?

谢谢,J

推荐答案

我的理解是,如果您使用 HQL 执行此操作,您将创建一个带有过滤器的笛卡尔连接,而不是内部连接.条件查询不支持这样做.

My understanding is that if you do this using HQL, you are creating a Cartesian join with a filter, rather than an inner join. Criteria queries do not support doing this.

这篇关于Hibernate 标准:在没有映射关联的情况下连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆