I would like to create a JPQL query that shows the list of users in the same group as the logged in user.
Indeed, that's what I already did
public List<Utilisateur> getListUser(Long id) {
return getEntityManager()
.createQuery("SELECT u FROM Utilisateur u WHERE u.group.id =:" +id)
.getResultList();
}
and my User tables is as follows
User: id, name, tel, email, group, ...
Group: id, name, type.
My method to retrieve the group of the current user
public Long currentIdGroup() {
Utilisateur usere = EntityRealm.getUser();
if (usere == null) {
return null;
}
return EntityRealm.getUser().getGroup().getId();
}
The declaration of the list in the Bean.
public List<Utilisateur> getListusersGroup() {
return this.utilisateurService.getListUser(currentIdGroup());
}
But, I'm getting this error in 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.
Thank you in advance for your crucial help.
Many things to you.