这一节主要是一些实体类
2. 实体类
Users.java
- package com.base.entity;
- import java.io.Serializable;
- import java.util.HashSet;
- import java.util.Set;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.Id;
- import javax.persistence.JoinTable;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToMany;
- import javax.persistence.Table;
- /**
- *
- * User Entity
- *
- * @author Administrator
- * @since 25 Mar 2012
- * @version 1.0.0
- *
- */
- @Entity
- @Table(name="users")
- public class Users implements Serializable
- {
- private static final long serialVersionUID = 1L;
- private int id;
- private int enable;
- private String account;
- private String password;
- private Set<Roles> roles = new HashSet<Roles>(0);
- public Users() {
- }
- public void setId(int id) {
- this.id = id;
- }
- @Id
- @Column(name="ID", unique = true, nullable = false)
- public int getId() {
- return id;
- }
- public void setAccount(String account) {
- this.account = account;
- }
- @Column(name="ACCOUNT", length = 50)
- public String getAccount() {
- return account;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- @Column(name="PASSWORD", length = 50)
- public String getPassword() {
- return password;
- }
- public void setEnable(int enable) {
- this.enable = enable;
- }
- @Column(name="ENABLE", length = 1)
- public int getEnable() {
- return enable;
- }
- public void setRoles(Set<Roles> roles) {
- this.roles = roles;
- }
- @ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
- @JoinTable(name="users_roles", joinColumns=@JoinColumn(name="uid"), inverseJoinColumns=@JoinColumn(name="rid"))
- public Set<Roles> getRoles() {
- return roles;
- }
- }
Roles.java
- package com.base.entity;
- import java.io.Serializable;
- import java.util.HashSet;
- import java.util.Set;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import javax.persistence.ManyToMany;
- import javax.persistence.Table;
- /**
- *
- * Roles Entity
- *
- * @author administrator
- * @since 2012.7.23
- * @version 1.0.0
- *
- */
- @Entity
- @Table(name="roles")
- public class Roles implements Serializable
- {
- private static final long serialVersionUID = 1L;
- private int id;
- private int enable;
- private String name;
- private Set<Users> users = new HashSet<Users>(0);
- private Set<Resources> resources = new HashSet<Resources>(0);
- public Roles() {
- }
- public void setId(int id) {
- this.id = id;
- }
- @Id
- @Column(name="ID", unique = true, nullable = false)
- public int getId() {
- return id;
- }
- public void setEnable(int enable) {
- this.enable = enable;
- }
- @Column(name="ENABLE", length = 1)
- public int getEnable() {
- return enable;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Column(name="NAME", length = 50)
- public String getName() {
- return name;
- }
- public void setUsers(Set<Users> users) {
- this.users = users;
- }
- @ManyToMany(mappedBy="roles")
- public Set<Users> getUsers() {
- return users;
- }
- public void setResources(Set<Resources> resources) {
- this.resources = resources;
- }
- @ManyToMany(mappedBy="roles")
- public Set<Resources> getResources() {
- return resources;
- }
- }
Resources.java
- package com.base.entity;
- import java.io.Serializable;
- import java.util.HashSet;
- import java.util.Set;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.JoinTable;
- import javax.persistence.ManyToMany;
- import javax.persistence.Table;
- /**
- *
- * Resources Entity
- *
- * @author administrator
- * @since 2012.7.23
- * @version 1.0.0
- *
- */
- @Entity
- @Table(name="resources")
- public class Resources implements Serializable
- {
- private static final long serialVersionUID = 1L;
- private String id;
- private String url;
- private int priority;
- private String type;
- private String name;
- private String memo;
- private Set<Roles> roles = new HashSet<Roles>(0);
- public Resources() {
- }
- public void setId(String id) {
- this.id = id;
- }
- @Id
- @Column(name="ID", unique = true, nullable = false)
- public String getId() {
- return id;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Column(name="NAME", length = 50)
- public String getName() {
- return name;
- }
- public void setType(String type) {
- this.type = type;
- }
- @Column(name="TYPE", length = 1)
- public String getType() {
- return type;
- }
- public void setUrl(String url) {
- this.url = url;
- }
- @Column(name="URL", length = 500)
- public String getUrl() {
- return url;
- }
- public void setPriority(int priority) {
- this.priority = priority;
- }
- @Column(name="PRIORITY", length = 50)
- public int getPriority() {
- return priority;
- }
- public void setMemo(String memo) {
- this.memo = memo;
- }
- @Column(name="MEMO", length = 500)
- public String getMemo() {
- return memo;
- }
- public void setRoles(Set<Roles> roles) {
- this.roles = roles;
- }
- @ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
- @JoinTable(name="roles_resources", joinColumns=@JoinColumn(name="rsid"), inverseJoinColumns=@JoinColumn(name="rid"))
- public Set<Roles> getRoles() {
- return roles;
- }
- }