在Hibernate投影时:
Criteria criteria = session.createCriteria(XYZ.class)
.add(Restrictions.eq("XYDId", 1)).add(Restrictions.eq("active", Boolean.TRUE));
criteria.setProjection(Projections.property("abc.id").as("id"));
criteria.setProjection(Projections.property("abc.timezoneKey").as("TIMEZONEKEY"));
criteria.setResultTransformer(Transformers.aliasToBean(abc.class));
抛出异常
could not resolve property: abc.timezoneKey of: com.locaid.gfe.common.entities.XYZ
虽然在XYZ实体中,abc作为proerty存在,而在abc timezoneKey作为属性存在。任何人都可以帮助我获得我所缺乏的东西。
答案 0 :(得分:0)
您需要为alias
属性
abc
Criteria criteria = session.createCriteria(XYZ.class, "xyz").createAlias("xyz.abc", "xabc").add(Restrictions.eq("xyz.XYDId", 1)).add(Restrictions.eq("xyz.active", Boolean.TRUE));
criteria.setProjection(Projections.property("xabc.id").as("id"));
criteria.setProjection(Projections.property("xabc.timezoneKey").as("TIMEZONEKEY"));
criteria.setResultTransformer(Transformers.aliasToBean(abc.class));
您还可以查看this。