如何使用 JPA Criteria API 导航对象图?
假设我们有以下类图:
public final class Address {
private final String streetAddress
public String getStreetAddress() {
return streetAddress;
}
}
public final class House {
private Address address;
}
现在我想使用 JPA Criteria API 查询与特定街道地址匹配的所有房屋。我尝试这样做,但没有成功。
addPredicate(criteriaBuilder.like(root.<String>get("address.streetAddress"), streetAddress));
Suppose we have the following class graph:
public final class Address {
private final String streetAddress
public String getStreetAddress() {
return streetAddress;
}
}
public final class House {
private Address address;
}
Now I want to query all the houses that match an specific street address using JPA Criteria API. I tried to do this but it did not work.
addPredicate(criteriaBuilder.like(root.<String>get("address.streetAddress"), streetAddress));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过这样做解决了这个问题:
I solved this problem by doing: