我有我无法解决的错误。

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

}

最佳答案

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/

10-13 04:31