我有以下实体 -
UserDB{
String name;
Address address;
//getter Setter of name & address
}
User{
String name;
Address address;
//getter Setter of name & address
}
Address{
String line1;
String line2;
String postalCode;
//getter setter of line1,line2,postalCode
}
我们可以在hibernate Projections中设置嵌套属性,如下所示吗?不使用第三方插件
public User getUserInfo(Long id) {
Criteria criteria = getCriteria(UserDB.class);
criteria.createAlias("addressDB", "addDbAlias", JoinType.INNER_JOIN);
criteria.setProjection(Projections.projectionList()
.add(Projections.property("name").as("name"))
.add(Projections.property("addDbAlias.line1").as("address.line1")) //is this ".as(address.line1)" correct way? If not how to achieve this
.add(Projections.property("addDbAlias.line2").as("address.line2"))
.add(Projections.property("addDbAlias.postalCode").as("address.postalCode")));
criteria.add(Restrictions.eq("id", id));
上面的代码给出错误:引起:org.hibernate.PropertyNotFoundException:找不到用户上的address.line1的setter
如何解决此错误..在此先感谢!!