JPQL:错误编译 - 状态字段“e.e2.e3”无法解析为有效类型
Posted
技术标签:
【中文标题】JPQL:错误编译 - 状态字段“e.e2.e3”无法解析为有效类型【英文标题】:JPQL: error compiling - state field 'e.e2.e3' cannot be resolved to a valid type 【发布时间】:2014-05-26 17:18:40 【问题描述】:我有这个我无法解决的错误。
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.
命名查询:
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;
道:
@Override
public List<ResourceGroup> getAllowedResourceGroups(UserGroup userGrp)
return this.em.createNamedQuery("ResourceGroup.getAllCanView")
.setParameter("userGroup", userGrp)
.setParameter("canView", true)
.getResultList();
【问题讨论】:
【参考方案1】:e.aclUserResourceGroups
是一个集合,您无法通过这种方式访问它。
未测试,但尝试如下:
SELECT e
FROM ResourceGroup e
inner join e.aclUserResourceGroups acl
WHERE acl.userGroup=:userGroup
AND acl.canView=:canView
希望这会有所帮助!
【讨论】:
以上是关于JPQL:错误编译 - 状态字段“e.e2.e3”无法解析为有效类型的主要内容,如果未能解决你的问题,请参考以下文章