Java HQL查询集合中的列
使用HQL和这样的配置是否可以访问表2的各个列Java HQL查询集合中的列,java,hibernate,hql,Java,Hibernate,Hql,使用HQL和这样的配置是否可以访问表2的各个列 <hibernate-mapping> <class table="table1"> <set name="table2" table="table2" lazy="true" cascade="all"> <key column="result_id"/> <many-to-many column="group_id"/> </set&g
<hibernate-mapping>
<class table="table1">
<set name="table2" table="table2" lazy="true" cascade="all">
<key column="result_id"/>
<many-to-many column="group_id"/>
</set>
</class>
</hibernate-mapping>
它们只是table1的table2属性的属性
select t1.table2.property1, t1.table2.property2, ... from table1 as t1
你可能不得不这样加入
select t2.property1, t2.property2, ...
from table1 as t1
inner join t1.table2 as t2
以下是的相关部分。您可以查询它们,但不能将其作为where子句的一部分。例如:
select t1.table2.x from table1 as t1
会有用的,但是
select t1 from table1 as t1 where t1.table2.x = foo
不会。假设table2有一列“
color varchar(128)
”,该列正确映射到Hibernate
您应该能够执行以下操作:
from table1 where table2.color = 'red'
这将返回链接到table2
行(其color
列为“红色”)的所有table1
行。请注意,在Hibernate映射中,集合
与它引用的表具有相同的名称。上面的查询使用集合的名称,而不是表的名称