1
我有点麻烦。我正在使用JPA标准进行动态选择(使用条件作为where子句具有可选变量...),但我的实体之一有一个EmbeddedId,其中包含用户列,其中需要检查用户ID ...JPA标准和EmbeddedId上的谓词
这里是我的实体。
@Entity
@Table(name = "user_like")
public class UserLike extends AbstractTimestampEntity implements Serializable {
@EmbeddedId
private UserLike.userLikePK userLikePK= new UserLike.UserLikePK();
...
with all the setter and gets
...
@Embeddable
public static class UserLike implements Serializable{
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
... (and an other column, not important for now=
}
}
用户是包含该列的userId
,现在这是我的查询看起来像其他实体。
Root<Poi> p = cq.from(Poi.class);
Join<Poi,UserLike> ul = p.join("userLike");
List<Predicate> predicates = new ArrayList<Predicate>();
Predicate predicate = cb.like(cb.upper(p.<String>get("name")), "%" + poiName.toUpperCase() + "%");
predicates.add(predicate);
Predicate predicate2 = cb.equal(ul.get("userLikePK.user.idUser"), userId);
predicates.add(predicate);
//multi select because i need some info from p and ul as well....
cq.multiselect(p, ul);
现在predicate2明显扔我一个错误“无法找到与属性的给定名称[userPoiLikePK.user.idUser]”
谁能告诉我怎么可以加我“等于”谓词用户ID?
PS:这是PA查询我要存档:
SELECT p,ul FROM Poi p LEFT JOIN p.userLike ul WHERE p.name like :name AND ul.user.idUser=:userId
谢谢!!
感谢它的工作! – Johny19 2014-11-21 13:03:18