Hibernate条件API与#34;在第34条中;

时间:2015-04-14 17:44:33

标签: hibernate hibernate-criteria

我有原生SQL,我想转移到Hibenate的标准API,

这是:

SELECT *
FROM HV_LMA_VI t0
WHERE t0.HV_ID IN
              (SELECT t2.HV_ID
               FROM Z_LSZERG_HV t4,
                    Z_LSZ_ERG t3,
                    HERSTELLUNGSVARIANTE t2
               WHERE ((t3.LSZ_ID = 204)
                      AND ((t4.HV_ID = t2.HV_ID)
                      AND ((t3.ERG_ID = t4.ERG_ID)
                      AND (t3.LSZ_ID = t4.LSZ_ID)))));

存在所有需要的诱惑(HV_LMA_VI, Z_LSZERG_HV, Z_LSZ_ERG,)

1 个答案:

答案 0 :(得分:1)

根据我对您的查询的理解,它将接近:

DetachedCriteria detachedCriteria = DetachedCriteria.forClass(HERSTELLUNGSVARIANTE.class)
    .createAlias("propertyToT3", "t3")
    .createAlias("t3.propertyToT4", "t4")
    .add(Restrictions.eq("t3.LSZ_ID", 204))
    .setProjection(Projections.property("HV_ID"));
session.createCriteria(HV_LMA_VI.class)
    .add(Property.forName("HV_ID").in(detachedCriteria))
    .list();