0

我有一个Subject有两个字段Collection<Ownership> ownershipFromCollection<Ownership> ownershipTo. 该类Ownership有两个字段,Subject owner并且Subject owned

要获取主题及其集合,我目前正在执行以下操作:

from Subject s left join fetch s.ownershipFrom left join fetch s.ownershipTo.

这可行,但对我来说似乎效率不高,因为我访问同一张表(所有权)两次,我相信我只能访问一次。有没有更好的方法来获取这些类?

4

1 回答 1

0

我将从Ownership对象而不是Subject. 例子:

select own
from Ownership own, Subject s
where own.ownershipFrom = s
or own.ownershipTo = s

类似的东西。

查看以下链接可能有用:http: //docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

于 2012-06-15T21:21:24.043 回答