Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.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 hibernate标准_Java_Hibernate_Criteria - Fatal编程技术网

java hibernate标准

java hibernate标准,java,hibernate,criteria,Java,Hibernate,Criteria,我的数据库中有以下表结构: Table A: Table B: Table C: _______________________ ______________________________ ______________________ | Field | Type | Key | | Field | Type | Key | | Field | Type | Ke

我的数据库中有以下表结构:

 Table A:                     Table B:                       Table C:
 _______________________      ______________________________  ______________________
 | Field | Type | Key  |     | Field | Type | Key          |  | Field | Type | Key  |   
 ______________________|     |_____________________________|  |_____________________|
 | a_id  | Int  | PRI  |     | a_id  | Int  | FK of A(a_id)|  | c_id  | Int  | PRI  |
 |     ...       ...   |     | c_id  | Int  | FK of C(c_id)|  |       ...           |
 |_____________________|      ______________________________  |_____________________|
目标是:

  class A {
        List<C> list;
        ...
   }
下面是一个SQL查询,它为我提供了正确的结果,现在应该在一个条件中进行“转换”:

 select c.* 
 from A as a, 
      B as b, 
      C as c 
 where a.a_id = b.a_id and b.c_id = c.c_id;
有人知道如何制定标准吗?

如果有

class A {
    List<C> list;
    ...
}
此时,如果您执行
criteria.list()
操作,您将获得所有
a
对象,每个对象都有一个
C
值列表,其中只有ID。为了获得完整的C对象,您需要额外的:

criteria.createAlias("list", "listC");
这将为
A
C
创建一个别名(即内部连接)。现在,假设您有一个a(属于
a
)类,您可以执行
a.getList().get(i).getWhateverFieldFromC()
;现在,您已经为
A
的每个实例填充了
C
s的列表

不要忘记在最后执行
criteria.list()
检索列表。就这些了


p.S.这是假设(当然)实体
A
C
正确映射。

您尝试过使用HQL而不是标准api吗?您的实体看起来如何?所有其他数据库访问都是使用标准完成的,因此我希望坚持使用该标准;我添加了有效的SQL查询,并且应该在条件中“翻译”该查询
// Create criteria on class A
Criteria criteria = session.createCriteria(A.class);
criteria.createAlias("list", "listC");