1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.samples.sprhib.model;
20
21 import org.hibernate.annotations.Cache;
22 import org.hibernate.annotations.CacheConcurrencyStrategy;
23 import org.hibernate.annotations.CollectionOfElements;
24 import org.hibernate.annotations.Index;
25
26 import javax.persistence.*;
27 import java.util.Set;
28
29
30
31
32 @Entity
33 @Table(name="roles")
34 @Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
35 public class Role {
36
37 private Long id;
38
39 private String name;
40
41 private String description;
42
43 private Set<String> permissions;
44
45 protected Role() {
46 }
47
48 public Role(String name) {
49 this.name = name;
50 }
51
52
53 @Id
54 @GeneratedValue
55 public Long getId() {
56 return id;
57 }
58
59 public void setId(Long id) {
60 this.id = id;
61 }
62
63 @Basic(optional=false)
64 @Column(length=100)
65 @Index(name="idx_roles_name")
66 public String getName() {
67 return name;
68 }
69
70 public void setName(String name) {
71 this.name = name;
72 }
73
74 @Basic(optional=false)
75 @Column(length=255)
76 public String getDescription() {
77 return description;
78 }
79
80 public void setDescription(String description) {
81 this.description = description;
82 }
83
84 @CollectionOfElements
85 @JoinTable(name="roles_permissions")
86 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
87 public Set<String> getPermissions() {
88 return permissions;
89 }
90
91 public void setPermissions(Set<String> permissions) {
92 this.permissions = permissions;
93 }
94
95 }
96
97