集合投影和嵌套投影
第一部分是如何投影集合?
我们可以对集合元素应用投影吗? 例如,
class User{
private address List<Address>;
}
class Address{
private String city;
private String state;
}
现在我可以只加载 User 类的地址属性吗?使用如下代码:
criteria.setProjection(Projections.property("Address"));
但它总是返回 null,即使对象确实设置了地址字段。 有什么不同的方式来投影收藏品吗?
第二部分:嵌套投影。 考虑与上面所示相同的模型,但不是有一个 Address 集合,而是有一个元素。 现在,如果我只想加载属于 User 类一部分的 Address 的“city”属性怎么办?
我尝试这样做:
Projections.property("Address.City")
但它给了我错误,指出无法解析用户的属性:“Address.City”。
是否有投影集合元素和嵌套投影的规定?
The first part is HOW TO PROJECT COLLECTIONS?
Can We apply projections on collection elements?
For e.g
class User{
private address List<Address>;
}
class Address{
private String city;
private String state;
}
Now can I just load the address attribute of User class? Using code like :
criteria.setProjection(Projections.property("Address"));
But it always return me null, even when the object does have an address field set.
Is there any different way to project Collection Items??
THE SECOND PART : NESTED PROJECTIONS.
Consider the same model as shown above, but instead of having a collection of Address, there is an single element.
Now What if I want to just load the "city" attribute of Address which is an part of User class??
I tried doing :
Projections.property("Address.City")
But it gives me error, stating could not resolve property: "Address.City" of User.
Is there any provision for Projecting Collection elements and Nested Projections??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate 区分大小写。因此,请使用 address.city,而不是 Address.Cityity。如果它不起作用,请尝试使用别名,例如:
Hibernate is case sensitive. so instead of Address.City, use address.city. If it does not work, try to use alias, like :