我正在使用 spring 4.0.6 和 Hibernate 4.2.21 开发一个应用程序。我有一个实体如下:
public class A {
@OneToMany(mappedBy="parent", fetch = FetchType.LAZY)
private Set<A> children = new HashSet<A>(0);
@ManyToOne(fetch = FetchType.EAGER)
private A parent;
/*
*
* Getters And Setters
*/
}
换句话说,A
实体是一棵树。现在我想保护树的所有节点。考虑以下树:
Node-1
Node-1.1
Node-1.1.1
Node-1.1.2
Node-1.2
Node-1.3
Node-2
Node-3
Node-3.1
Node-3.2
Node-3.3
我保护节点如下:
@PostFilter("hasPermission(filterObject, 'read')")
public List<A> getAll() {}
Node-1
此代码保护第一级( ,Node-2
& Node-3
)中的节点。现在我们想要read
在Node-1
, Node-1.1
&Node-1-2
节点中获得用户访问权限。我们如何实现它?