我有3个实体-usergroup,user,usergroupmemberships。usergroupmemberships对user和usergroup都有1比1。我想用他的身份证在用户组里找一个
以下查询适用于my db:
SELECT *
FROM UserGroup g
JOIN UserGroupMembership ON
UserGroupMembership.usergroup_id = g.id
WHERE UserGroupMembership.user_id = 868
野蝇:
与使用来自entitymanager的查询的JavaREST帖子不带nullpointerexception相同
SELECT g
FROM UserGroup g
JOIN UserGroupMembership
ON UserGroupMembership.usergroup = g.id
WHERE UserGroupMembership.user = :id
我如何正确地写这个?
尝试了不同的方法来编写查询,并尝试在wildfly和javaee上编写用户id im
public List<UserGroup> findUserGroupbyUser(long id) {
return em.createQuery("SELECT g FROM UserGroup g JOIN
UserGroupMembership ON UserGroupMembership.usergroup = g WHERE
UserGroupMembership.user.id = :id", UserGroup.class).setParameter("id",
id).getResultList();
}
@Entity
public class UserGroupMembership {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne(cascade = CascadeType.ALL)
private UserGroup usergroup;
@OneToOne(cascade = CascadeType.ALL)
private User user;
预期结果是1个条目
暂无答案!
目前还没有任何答案,快来回答吧!