[Framework>>Hibernate>>View] Hibernate 试图View映射
一、SQL
CREATE OR REPLACE VIEW `vsys_user_module` AS select `tmu`.`module_id` AS `kmid`,`tmu`.`user_id` AS `kuid`,`turm`.`module_id` AS `module_id`, `turm`.`user_id` AS `user_id`,`tmu`.`parent_id` AS `parent_id`,`tmu`.`open_mode` AS `open_mode`, `tmu`.`module_name` AS `module_name`,`tmu`.`route` AS `route`,`tmu`.`enable` AS `enable`,`tmu`.`leaf` AS `leaf`, `tmu`.`checked` AS `checked`,`tmu`.`open` AS `open`,`tmu`.`module_class` AS `module_class`, `tmu`.`tab_name` AS `tab_name` from (((select `tm`.`module_id` AS `module_id`,`tm`.`parent_id` AS `parent_id`, `tm`.`module_name` AS `module_name`,`tm`.`open_mode` AS `open_mode`,`tm`.`route` AS `route`, `tm`.`enable` AS `enable`,`tm`.`leaf` AS `leaf`,`tm`.`checked` AS `checked`,`tm`.`open` AS `open`, `tm`.`module_class` AS `module_class`,`tm`.`tab_name` AS `tab_name`,`tu`.`user_id` AS `user_id` from (((select `zytrc_util`.`system_module`.`module_id` AS `module_id`, `zytrc_util`.`system_module`.`parent_id` AS `parent_id`, `zytrc_util`.`system_module`.`module_name` AS `module_name`, `zytrc_util`.`system_module`.`open_mode` AS `open_mode`, `zytrc_util`.`system_module`.`route` AS `route`, `zytrc_util`.`system_module`.`enable` AS `enable`, `zytrc_util`.`system_module`.`leaf` AS `leaf`, `zytrc_util`.`system_module`.`checked` AS `checked`, `zytrc_util`.`system_module`.`open` AS `open`, `zytrc_util`.`system_module`.`module_class` AS `module_class`, `zytrc_util`.`system_module`.`tab_name` AS `tab_name` from `zytrc_util`.`system_module`)) `tm` join (select `zytrc_util`.`system_user`.`id` AS `user_id` from `zytrc_util`.`system_user`) `tu`))) `tmu` left join (select `tur`.`user_id` AS `user_id`,max(`trm`.`module_id`) AS `module_id` from (`zytrc_util`.`system_user_role` `tur` join `zytrc_util`.`system_role_module` `trm` on((`tur`.`role_id` = `trm`.`role_id`))) group by `tur`.`user_id`,`trm`.`module_id`) `turm` on(((`tmu`.`module_id` = `turm`.`module_id`) and (`tmu`.`user_id` = `turm`.`user_id`)))) where (`tmu`.`enable` = '1') order by `tmu`.`module_id`;
二、VsysUserModule.hbm.xml文件
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="org.zytrc.orm.view.VsysUserModule" table="vsys_user_module" catalog="zytrc_util"> <composite-id name="id" class="org.zytrc.orm.view.VsysUserModuleId"> <key-property name="kuid" type="java.lang.Integer"> <column name="kuid" /> </key-property> <key-property name="kmid" type="java.lang.String"> <column name="kmid" length="10" /> </key-property> </composite-id> <property name="userId" type="java.lang.Integer"> <column name="user_id" /> </property> <property name="moduleId" type="java.lang.String"> <column name="module_id" length="10" /> </property> <property name="parentId" type="java.lang.String"> <column name="parent_id" length="10" /> </property> <property name="moduleName" type="java.lang.String"> <column name="module_name" length="40" /> </property> <property name="openMode" type="java.lang.String"> <column name="open_mode" length="10" /> </property> <property name="route" type="java.lang.String"> <column name="route" length="500" /> </property> <property name="enable" type="java.lang.String"> <column name="enable" length="1" /> </property> <property name="leaf" type="java.lang.String"> <column name="leaf" length="1" /> </property> <property name="checked" type="java.lang.String"> <column name="checked" length="45" /> </property> <property name="open" type="java.lang.String"> <column name="open" length="45" /> </property> <property name="moduleClass" type="java.lang.String"> <column name="module_class" length="45" /> </property> <property name="tabName" type="java.lang.String"> <column name="tab_name" length="45" /> </property> </class> </hibernate-mapping>
三、VsysUserModule.java和VsysUserModuleId.java
public class VsysUserModuleId implements java.io.Serializable { // Fields private Integer kuid; private String kmid; // Constructors /** default constructor */ public VsysUserModuleId() { } /** full constructor */ // Property accessors public Integer getKuid() { return kuid; } public VsysUserModuleId(Integer kuid, String kmid) { super(); this.kuid = kuid; this.kmid = kmid; } public void setKuid(Integer kuid) { this.kuid = kuid; } public String getKmid() { return kmid; } public void setKmid(String kmid) { this.kmid = kmid; } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((kmid == null) ? 0 : kmid.hashCode()); result = prime * result + ((kuid == null) ? 0 : kuid.hashCode()); return result; } }
public class VsysUserModule implements java.io.Serializable { // Fields private VsysUserModuleId id; private String parentId; private String moduleName; private String openMode; private String route; private String enable; private String leaf; private String checked; private String open; private String moduleClass; private String tabName; private String moduleId; private Integer userId; // Constructors /** default constructor */ public VsysUserModule() { } // Property accessors public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public VsysUserModule(VsysUserModuleId id, String parentId, String moduleName, String openMode, String route, String enable, String leaf, String checked, String open, String moduleClass, String tabName, String moduleId, Integer userId) { super(); this.id = id; this.parentId = parentId; this.moduleName = moduleName; this.openMode = openMode; this.route = route; this.enable = enable; this.leaf = leaf; this.checked = checked; this.open = open; this.moduleClass = moduleClass; this.tabName = tabName; this.moduleId = moduleId; this.userId = userId; } public VsysUserModuleId getId() { return this.id; } public void setId(VsysUserModuleId id) { this.id = id; } public String getParentId() { return parentId; } public void setParentId(String parentId) { this.parentId = parentId; } public String getModuleName() { return moduleName; } public void setModuleName(String moduleName) { this.moduleName = moduleName; } public String getOpenMode() { return openMode; } public void setOpenMode(String openMode) { this.openMode = openMode; } public String getRoute() { return route; } public void setRoute(String route) { this.route = route; } public String getEnable() { return enable; } public void setEnable(String enable) { this.enable = enable; } public String getLeaf() { return leaf; } public void setLeaf(String leaf) { this.leaf = leaf; } public String getChecked() { return checked; } public void setChecked(String checked) { this.checked = checked; } public String getOpen() { return open; } public void setOpen(String open) { this.open = open; } public String getModuleClass() { return moduleClass; } public void setModuleClass(String moduleClass) { this.moduleClass = moduleClass; } public String getTabName() { return tabName; } public void setTabName(String tabName) { this.tabName = tabName; } public String getModuleId() { return moduleId; } public void setModuleId(String moduleId) { this.moduleId = moduleId; } @Override public String toString() { return "VsysUserModule [id=" + id + ", parentId=" + parentId + ", moduleName=" + moduleName + ", openMode=" + openMode + ", route=" + route + ", enable=" + enable + ", leaf=" + leaf + ", checked=" + checked + ", open=" + open + ", moduleClass=" + moduleClass + ", tabName=" + tabName + ", moduleId=" + moduleId + ", userId=" + userId + "]"; } }
浙公网安备 33010602011771号