【发布时间】:2018-01-24 21:04:32
【问题描述】:
我想创建一个 JPQL 查询,该查询显示与登录用户在同一组中的用户列表。
确实,我已经这样做了
public List<Utilisateur> getListUser(Long id) {
return getEntityManager()
.createQuery("SELECT u FROM Utilisateur u WHERE u.group.id =:" +id)
.getResultList();
}
我的用户表如下
用户:id、姓名、电话、电子邮件、组...
组:id、名称、类型。
我获取当前用户组的方法
public Long currentIdGroup() {
Utilisateur usere = EntityRealm.getUser();
if (usere == null) {
return null;
}
return EntityRealm.getUser().getGroup().getId();
}
Bean中列表的声明。
public List<Utilisateur> getListusersGroup() {
return this.utilisateurService.getListUser(currentIdGroup());
}
但是,我在 glassfish 中遇到了这个错误
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing [SELECT u FROM Utilisateur u WHERE u.group.id =:1]. [51, 53] The named input parameter ''{0}'' is not following the rules for a Java identifier.
提前感谢您的重要帮助。
给你很多东西。
【问题讨论】:
-
去掉冒号