本人是新手,刚刚接触hibernate不到2个星期,可能在很多人眼里这是一个非常简单的语句,可是他浪费了我1天的时间,希望对新手有所帮助。
这是一个根据登录人员ID取相应菜单的语句,权限取人员和角色权限的合集。
人员表:SysUser
字段:UserCode,UserName
机构表:SysOrganization
字段:OrgCode,OrgName
菜单表:SysMenu
字段:MenuID,MenuName,FuncID
角色表:SysRole
字段:RoleCode,RoleName
功能表:SysFunction
字段:FuncID,FuncName
人员角色关联表:O_Role_User
字段:oid,RoleCode,UserCode
人员功能关联表:O_Func_User
字段:oid,FuncID,UserID
角色功能关联表:O_Func_Role
字段:oid,FuncID,RoleID
人员和角色跟功能关联,功能跟菜单关联
对应的SQL语句应该是:
[code]
select * from Sys_Menu a
where func_id in
(select func_id from o_func_user where user_code=2000000000)
or func_id in(
select func_id from o_func_role a
left join o_role_user b on a.role_code = b.role_code
where b.user_code=2000000000
)
[/code]
对应的字段不太一样,但是可以看明白。
对应的HQL是:
[code]
String queryString = "select sysmenu from SysMenu sysmenu "
+ "inner join sysmenu.sysFunction func where func.funcId in "
+ "(select func.funcId from OFuncUser fu "
+ "left join fu.sysFunction func "
+ "left join fu.sysUser su where su.userCode=2000000000) "
+ "or func.funcId in "
+ "(select func.funcId from OFuncRole fr "
+ "left join fr.sysFunction func "
+ "left join fr.sysRole sr "
+ "left join sr.ORoleUsers ru "
+ "left join ru.sysUser su "
+ "where su.userCode=2000000000)";
[/code]
相信有更简单方便的方法。
这是一个根据登录人员ID取相应菜单的语句,权限取人员和角色权限的合集。
人员表:SysUser
字段:UserCode,UserName
机构表:SysOrganization
字段:OrgCode,OrgName
菜单表:SysMenu
字段:MenuID,MenuName,FuncID
角色表:SysRole
字段:RoleCode,RoleName
功能表:SysFunction
字段:FuncID,FuncName
人员角色关联表:O_Role_User
字段:oid,RoleCode,UserCode
人员功能关联表:O_Func_User
字段:oid,FuncID,UserID
角色功能关联表:O_Func_Role
字段:oid,FuncID,RoleID
人员和角色跟功能关联,功能跟菜单关联
对应的SQL语句应该是:
[code]
select * from Sys_Menu a
where func_id in
(select func_id from o_func_user where user_code=2000000000)
or func_id in(
select func_id from o_func_role a
left join o_role_user b on a.role_code = b.role_code
where b.user_code=2000000000
)
[/code]
对应的字段不太一样,但是可以看明白。
对应的HQL是:
[code]
String queryString = "select sysmenu from SysMenu sysmenu "
+ "inner join sysmenu.sysFunction func where func.funcId in "
+ "(select func.funcId from OFuncUser fu "
+ "left join fu.sysFunction func "
+ "left join fu.sysUser su where su.userCode=2000000000) "
+ "or func.funcId in "
+ "(select func.funcId from OFuncRole fr "
+ "left join fr.sysFunction func "
+ "left join fr.sysRole sr "
+ "left join sr.ORoleUsers ru "
+ "left join ru.sysUser su "
+ "where su.userCode=2000000000)";
[/code]
相信有更简单方便的方法。