ssh框架权限管理的小问题,初学者求解答

ssh框架权限管理,有三个实体类user role(角色) function(权限) 用manytomany将他们关联起来,那在拿到user之后如何拿到该用户的权限

这就是一个sql问题,每个用户都有角色,然后,角色都给他分配了权限,然后权限下面,有对应的页面展示,这样说,就很明白了把。

package com.wangl.sshsimple.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

@Entity
public class TbFunction {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long functionId;
private String functionName;
private String url;
private String memo;
@ManyToMany(mappedBy="functions")
private List roles;

public List<TbRole> getRoles() {
    return roles;
}
public void setRoles(List<TbRole> roles) {
    this.roles = roles;
}
public String getMemo() {
    return memo;
}
public void setMemo(String memo) {
    this.memo = memo;
}
public Long getFunctionId() {
    return functionId;
}
public void setFunctionId(Long functionId) {
    this.functionId = functionId;
}
public String getFunctionName() {
    return functionName;
}
public void setFunctionName(String functionName) {
    this.functionName = functionName;
}
public String getUrl() {
    return url;
}
public void setUrl(String url) {
    this.url = url;
}
@Override
public String toString() {
    return "TbFunction [functionId=" + functionId + ", functionName=" + functionName + ", url=" + url + "]";
}

}
package com.wangl.sshsimple.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;

@Entity
public class TbRole {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long roleId;
private String roleName;
private String description;
@ManyToMany(fetch=FetchType.EAGER)
private List functions;
@ManyToMany(mappedBy="roles")
private List users;

public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
public List<TbFunction> getFunctions() {
    return functions;
}
public void setFunctions(List<TbFunction> functions) {
    this.functions = functions;
}
public List<TbUser> getUsers() {
    return users;
}
public void setUsers(List<TbUser> users) {
    this.users = users;
}
public Long getRoleId() {
    return roleId;
}
public void setRoleId(Long roleId) {
    this.roleId = roleId;
}
public String getRoleName() {
    return roleName;
}
public void setRoleName(String roleName) {
    this.roleName = roleName;
}

}
package com.wangl.sshsimple.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

@Entity
public class TbUser {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long userId;
private String userName;
private String userPassword;
private String pName;
private String phoneNo;
@ManyToMany(fetch=FetchType.EAGER)
private List roles;

public String getpName() {
    return pName;
}
public void setpName(String pName) {
    this.pName = pName;
}
public String getPhoneNo() {
    return phoneNo;
}
public void setPhoneNo(String phoneNo) {
    this.phoneNo = phoneNo;
}
public List<TbRole> getRoles() {
    return roles;
}
public void setRoles(List<TbRole> roles) {
    this.roles = roles;
}

public String getUserPassword() {
    return userPassword;
}
public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
}
public Long getUserId() {
    return userId;
}
public void setUserId(Long userId) {
    this.userId = userId;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}
@Override
public String toString() {
    return "TbUser [userId=" + userId + ", userName=" + userName + "]";
}

}
数据库中已经关联起来了啊,但是是有user.getRoles的时候就是拿不到roles,本来我想着是缓存的问题,但是拿到currentsession,然后对其进行了refresh还是拿不到,这是为什么?