Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HQL查询集合中的列_Java_Hibernate_Hql - Fatal编程技术网

Java HQL查询集合中的列

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

使用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>
  </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映射中,
集合
与它引用的表具有相同的名称。上面的查询使用集合的名称,而不是表的名称