我有这个错误,我无法解决。
Exception Description: Problem compiling [SELECT e FROM ResourceGroup e WHERE e.aclUserResourceGroups.userGroup=:userGroup AND e.aclUserResourceGroups.canView=:canView].
[36, 69] The state field path 'e.aclUserResourceGroups.userGroup' cannot be resolved to a valid type.
[87, 118] The state field path 'e.aclUserResourceGroups.canView' cannot be resolved to a valid type.
NamedQuery:
SELECT e
FROM ResourceGroup e
WHERE e.aclUserResourceGroups.userGroup=:userGroup
AND e.aclUserResourceGroups.canView=:canView
ERD:
实体:
@Entity
@Table(name="resource_group")
public class ResourceGroup implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(unique=true)
private String name;
@OneToMany(mappedBy = "resourceGroup", cascade = CascadeType.ALL, fetch=FetchType.LAZY, orphanRemoval=true)
@JoinColumn(name = "resourcegroup_id")
private List<UserGroupResourceGroup> aclUserResourceGroups;
}
加入实体:
@Entity
@Table(name="user_group_resource_group")
public class UserGroupResourceGroup implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@ManyToOne(targetEntity = UserGroup.class, cascade = CascadeType.PERSIST, fetch=FetchType.LAZY)
@JoinColumn(name="usergroup_id")
private UserGroup userGroup = new UserGroup();
@ManyToOne(targetEntity = ResourceGroup.class, cascade = CascadeType.PERSIST, fetch=FetchType.LAZY)
@JoinColumn(name="resourcegroup_id")
private ResourceGroup resourceGroup = new ResourceGroup()
}
群组:
@Entity
@Table(name="user_group")
public class UserGroup implements Serializable{
@OneToMany(mappedBy="userGroup", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "usergroup_id")
private List<AccessControlList> acl;
@OneToMany(mappedBy="userGroup", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "usergroup_id")
private List<UserGroupResourceGroup> aclUserResourceGroups;
}
DAO:
@Override
public List<ResourceGroup> getAllowedResourceGroups(UserGroup userGrp){
return this.em.createNamedQuery("ResourceGroup.getAllCanView")
.setParameter("userGroup", userGrp)
.setParameter("canView", true)
.getResultList();
}
答案 0 :(得分:2)
e.aclUserResourceGroups
是一个集合,您无法以这种方式访问它。
未经测试,但请尝试使用以下内容:
SELECT e
FROM ResourceGroup e
inner join e.aclUserResourceGroups acl
WHERE acl.userGroup=:userGroup
AND acl.canView=:canView
希望这有帮助!