ns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "resource_id"))
31. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
32. private Set<Resource> resources;
33.
34. // setters and getter
35.}
Spring Security 2配置精讲 上(13)
时间:2011-10-16
增加资源(Resource)的Entity定义:
Java代码
1.@Entity
2.@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
3.
4.public class Resource {
5.
6. @Id
7. @GeneratedValue
8. private Integer id;
9.
10. private String type;
11.
12. private String value;
13.
14. @ManyToMany(mappedBy = "resources", targetEntity = Role.class, fetch = FetchType.EAGER)
15. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
16. private Set<Role> roles;
17.
18. /**
19. * The default constructor
20. */
21. public Resource() {
22.
23. }
24.}
25.
26.@Entity
27.@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
28.
29.public class Resource {
30.
31. @Id
32. @GeneratedValue
33. private Integer id;
34.
35. private String type;
36.
37. private String value;
38.
39. @ManyToMany(mappedBy = "resources", targetEntity = Role.class, fetch = FetchType.EAGER)
40. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
41. private Set<Role> roles;
42.
43. /**
44. * The default constructor
45. */
46. public Resource() {
47.
48. }
49.}
注意他们之间的多对多关系,以及他们之间关联关系的缓存和lazy属性设置。 |