gpt4 book ai didi

java - JPQL:编译错误 - 状态字段 'e.e2.e3' 无法解析为有效类型

转载 作者:行者123 更新时间:2023-11-30 03:53:12 26 4
gpt4 key购买 nike

我遇到了无法解决的错误。

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:

enter image description here

实体:

@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();

}

最佳答案

e.aclUserResourceGroups 是一个集合,您无法以这种方式访问​​它。

未测试,但尝试使用以下内容:

SELECT e 
FROM ResourceGroup e
inner join e.aclUserResourceGroups acl
WHERE acl.userGroup=:userGroup
AND acl.canView=:canView

希望这有帮助!

关于java - JPQL:编译错误 - 状态字段 'e.e2.e3' 无法解析为有效类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23874988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com