我有以下课程
@NamedQueries({
@NamedQuery(name = "User.FindByFilter", query = "SELECT NEW myPkg.SimpleUser(u.name , u.email, u.roles) FROM User u WHERE UPPER(u.name) LIKE :filter AND ORDER BY u.name")
})
@Entity
@Table(name = "Users")
public class User implements Serializable, UserDetails {
@Id
private String email;
@Basic
private String name;
@OneToMany(cascade = { CascadeType.REFRESH, CascadeType.PERSIST }, fetch = FetchType.EAGER)
private Set<Authority> roles;
...
}
和
@Entity
public class Authority implements GrantedAuthority {
//just @Id and @Basic here no specific mapping back to user
...
}
我当然知道这个查询
@NamedQuery(name = "User.FindByFilter", query = "SELECT NEW myPkg.SimpleUser(u.name , u.email, u.roles) FROM User u WHERE UPPER(u.name) LIKE :filter AND ORDER BY u.name")
错了,因为u.roles
是@OneToMany
。
所以我的问题是将角色字段传递给const的正确方法是什么?