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.Index;
24
25 import javax.persistence.*;
26 import java.util.Set;
27
28
29
30
31 @Entity
32 @Table(name="roles")
33 @Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
34 public class Role {
35
36 private Long id;
37
38 private String name;
39
40 private String description;
41
42 private Set<String> permissions;
43
44 protected Role() {
45 }
46
47 public Role(String name) {
48 this.name = name;
49 }
50
51
52 @Id
53 @GeneratedValue
54 public Long getId() {
55 return id;
56 }
57
58 public void setId(Long id) {
59 this.id = id;
60 }
61
62 @Basic(optional=false)
63 @Column(length=100)
64 @Index(name="idx_roles_name")
65 public String getName() {
66 return name;
67 }
68
69 public void setName(String name) {
70 this.name = name;
71 }
72
73 @Basic(optional=false)
74 @Column(length=255)
75 public String getDescription() {
76 return description;
77 }
78
79 public void setDescription(String description) {
80 this.description = description;
81 }
82
83 @ElementCollection(targetClass=String.class)
84 @JoinTable(name="roles_permissions")
85 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
86 public Set<String> getPermissions() {
87 return permissions;
88 }
89
90 public void setPermissions(Set<String> permissions) {
91 this.permissions = permissions;
92 }
93
94 }
95
96