Java 复合键多对一未知列的Hibernate JPQL查询
我有一个查询,希望返回特定组中特定用户的GroupRole列表。GroupUserRoles是一个复合键,它保存用户、组和组角色ID。使用以下查询时,它似乎无法在GroupUserRoles中找到ManyTone映射的组:Java 复合键多对一未知列的Hibernate JPQL查询,java,mysql,spring,hibernate,jpql,Java,Mysql,Spring,Hibernate,Jpql,我有一个查询,希望返回特定组中特定用户的GroupRole列表。GroupUserRoles是一个复合键,它保存用户、组和组角色ID。使用以下查询时,它似乎无法在GroupUserRoles中找到ManyTone映射的组: @Query(value="SELECT groupRole FROM GroupRole groupRole " + "JOIN groupRole.groupUserRoles groupUserRoles "
@Query(value="SELECT groupRole FROM GroupRole groupRole " +
"JOIN groupRole.groupUserRoles groupUserRoles " +
"JOIN groupUserRoles.group groups "+
"JOIN groups.groupMembers groupMembers "+
"WHERE groupMembers.userID =:userID "+
"AND groups.groupID =:groupID")
我得到以下错误:java.sql.SQLSyntaxErrorException:on子句中的未知列“groupuserr1\uu.group\u groupID”
以下是我的实体
@Entity
@Table(name = "GroupRoles")
public class GroupRole {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long groupRoleID;
private String roleName;
@OneToMany(mappedBy = "groupRole", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<GroupUserRoles> groupUserRoles = new HashSet<>();
//
@Entity(name = "GroupUserRoles")
public class GroupUserRoles {
@EmbeddedId
private GroupUserRolesID id;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("groupRoleID")
private GroupRole groupRole;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("groupID")
private Group group;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("userID")
private User user;
public GroupUserRoles(GroupRole groupRole, Group group, User user) {
this.groupRole = groupRole;
this.group = group;
this.user = user;
this.id = new GroupUserRolesID(groupRole.getId(), group.getGroupID(), user.getUserId());
}
//
@Table(name="FocusGroups")
@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
property = "groupID")
public class Group {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long groupID;
private String groupName;
@ManyToMany
@JoinTable(name = "GroupMembers",
joinColumns = @JoinColumn(
name = "groupID"),
inverseJoinColumns = @JoinColumn(
name = "userID"))
private Set<User> groupMembers = new HashSet<>();
@OneToMany(mappedBy = "group")
//, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<GroupUserRoles> groupRoles = new HashSet<>();
//
@实体
@表(name=“GroupRoles”)
公共类组角色{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长群居区;
私有字符串roleName;
@OneToMany(mappedBy=“groupRole”,cascade=CascadeType.ALL,orphan=true)
private Set groupUserRoles=new HashSet();
//
@实体(name=“GroupUserRoles”)
公共类GroupUserRoles{
@嵌入ID
私有组用户角色id;
@manytone(fetch=FetchType.LAZY)
@MapsId(“groupRoleID”)
私人组角色组角色;
@manytone(fetch=FetchType.LAZY)
@MapsId(“组ID”)
私人集团;
@manytone(fetch=FetchType.LAZY)
@MapsId(“用户ID”)
私人用户;
公共组用户角色(组角色、组角色、用户){
this.groupRole=groupRole;
this.group=组;
this.user=用户;
this.id=新的GroupUserRoleId(groupRole.getId(),group.getGroupID(),user.getUserId());
}
//
@表(name=“FocusGroups”)
@实体
@JsonIdentityInfo(生成器=ObjectedGenerators.PropertyGenerator.class,
property=“groupID”)
公共课组{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私有长groupID;
私有字符串组名;
@许多
@JoinTable(name=“GroupMembers”,
joinColumns=@JoinColumn(
name=“groupID”),
inverseJoinColumns=@JoinColumn(
name=“userID”))
private Set groupMembers=new HashSet();
@OneToMany(mappedBy=“集团”)
//,cascade=CascadeType.ALL,orphan=true)
private Set groupRoles=new HashSet();
//