【问题标题】:Create a Hibernate Criteria sentence from sql [closed]从sql创建一个Hibernate Criteria语句[关闭]
【发布时间】:2014-09-22 13:27:51
【问题描述】:

如何从这个 SQL 查询创建 Hibernate Criteria???

select di.*
from device_information di,
category_product cp
where di.ID_CATEGORY_PRODUCT=cp.ID
and cp.ID_INTERNAL_GROUP= 345

其实我有这个代码行:

标准标准 = getSessionFactory().getCurrentSession().createCriteria(DeviceInformation.class); criteria.createCriteria("categoryProduct"); criteria.add(Restrictions.eq("internalGroup",internalGroupSelected)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

List list=criteria.list();

但我有这个错误:无法解析属性:internalGroup of: com.as5fx.business.model.DeviceInformation

【问题讨论】:

    标签: java sql hibernate criteria


    【解决方案1】:

    您的category_product 中有internalGroup 属性,因此当您在DeviceInformation 上查询时找不到该属性。 如果您在DeviceInformationcategoryProduct 之间有关系,请尝试如下:

    List list = getSessionFactory().getCurrentSession().createCriteria(DeviceInformation.class,"deviceInformation")
        .createAlias("deviceInformation.categoryProduct","product")
        .add(Restrictions.eq("product.internalGroup",internalGroupSelected))
        .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-08
      • 2012-10-20
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多