Hibernate 注解整理

package com.yuxinglab.admin.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class RolePermisson {
	@Id
	@GeneratedValue
	private int id;
	@ManyToOne
	@JoinColumn(name = "FK_PERMISSON_ID")
	private Permisson permisson;
	@ManyToOne
	@JoinColumn(name = "FK_ROLE_ID")
	private Role role;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Permisson getPermisson() {
		return permisson;
	}

	public void setPermisson(Permisson permisson) {
		this.permisson = permisson;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

}

 

package com.yuxinglab.admin.model;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "t_role")
public class Role {
	@Id
	@GeneratedValue
	private int id;
	private String roleName;
	private String descript;
	
	@OneToMany(mappedBy = "role")
	@LazyCollection(LazyCollectionOption.EXTRA)
	private Set<RolePermisson> permissons;
	@OneToMany(mappedBy = "role")
	private Set<User> users;

	public Set<RolePermisson> getPermissons() {
		return permissons;
	}

	public void setPermissons(Set<RolePermisson> permissons) {
		this.permissons = permissons;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getDescript() {
		return descript;
	}

	public void setDescript(String descript) {
		this.descript = descript;
	}

}

 

package com.yuxinglab.admin.model;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "t_permisson")
public class Permisson {

	@Id
	@GeneratedValue
	private int id;
	private String name;
	private String path;
	@OneToMany(mappedBy = "permisson")
	@LazyCollection(LazyCollectionOption.EXTRA)
	private Set<RolePermisson> roles;
	@OneToOne(mappedBy = "permisson")
	private Menu menu;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Set<RolePermisson> getRoles() {
		return roles;
	}

	public void setRoles(Set<RolePermisson> roles) {
		this.roles = roles;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

}

 

package com.yuxinglab.admin.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class User {
	@Id
	@GeneratedValue
	private int id;
	@ManyToOne
	@JoinColumn(name = "fk_role_id")
	private Role role;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

}

 

package com.yuxinglab.admin.model;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Menu {
	@Id
	@GeneratedValue
	private int id;
	private String name;

	@OneToOne
	@JoinColumn(name = "FK_PERMISSON_ID", unique = true)
	private Permisson permisson;

	// 多个菜单对应一个parent菜单
	@ManyToOne
	@JoinColumn(name = "FK_PARENT_MENU_ID")
	private Menu menu;

	@OneToMany(mappedBy = "menu")
	private Set<Menu> menus;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Permisson getPermisson() {
		return permisson;
	}

	public void setPermisson(Permisson permisson) {
		this.permisson = permisson;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public Set<Menu> getMenus() {
		return menus;
	}

	public void setMenus(Set<Menu> menus) {
		this.menus = menus;
	}

}

 

你可能感兴趣的:(Hibernate)