【问题标题】:how to create criteria for fetching data from two table using hibernate如何使用休眠创建从两个表中获取数据的标准
【发布时间】:2014-01-24 09:56:22
【问题描述】:

我想在休眠中使用这个查询从两个表中获取数据:

select info.gwid,info.companyId,info.gwUserId,info.create_dt,stat.status,stat.lastactivity from gwinfo as info JOIN gwstatusinfo as stat ON info.gwid=stat.gwid

我试过这样休眠:

Query query = session.createQuery("from SBoxInfo sinfo,SBoxStatus sstatus on sinfo.gwId = sstatus.gwId");
List<SBoxInfo> listOfSBoxs = (List<SBoxInfo>)query.list();

但它没有返回 SBoxInfo 类型的列表。我必须为此创建一个标准吗? 如何为上述查询创建条件以检索 SBoxInfo 类型列表中的结果?

【问题讨论】:

  • 你的“on”应该是“where”吗?
  • 这两张表是什么关系?
  • 一对一的关系

标签: hibernate hibernate-criteria


【解决方案1】:

通过创建这样的标准来完成:

Criteria ct = session.createCriteria(SBoxInfo.class);
ct.setFetchMode("SBoxStatus", FetchMode.JOIN);
List<SBoxInfo> listOfSBoxs = ct.list();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    • 2016-07-24
    • 2012-08-14
    • 2015-05-24
    • 1970-01-01
    • 2021-03-17
    相关资源
    最近更新 更多