设计好数据的表结构后,使用Middlegen-Hibernate工具很方便的生成hibernate的映射文件(Middlegen-Hibernate工具的使用方法不在这里介绍,可以到网上找找,很多的):
Middlegen-Hibernate启动后的界面如下:
生成后的映射文件具体内容如下
Labpermission.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cn.**.common.entity.LabPermission"
table="LAB_PERMISSION"
>
<id
name="permissionId"
type="java.lang.String"
column="PERMISSION_ID"
>
<generator class="assigned" />
</id>
<property
name="permissionName"
type="java.lang.String"
column="PERMISSION_NAME"
not-null="true"
length="100"
/>
<property
name="permissionDesc"
type="java.lang.String"
column="PERMISSION_DESC"
length="200"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to LabRolepermission -->
<set
name="labRolepermissions"
lazy="true"
inverse="true"
>
<key>
<column name="PERMISSION_ID" />
</key>
<one-to-many
class="cn.**.common.entity.LabRolepermission"
/>
</set>
</class>
</hibernate-mapping>
labRole.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cn.**.common.entity.LabRole"
table="LAB_ROLE"
>
<id
name="roleId"
type="int"
column="ROLE_ID"
>
<generator class="sequence">
<param name="sequence">LAB_ROLE_S</param>
</generator>
</id>
<property
name="roleName"
type="java.lang.String"
column="ROLE_NAME"
length="20"
not-null="true"
/>
<property
name="roleDesc"
type="java.lang.String"
column="ROLE_DESC"
length="100"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to LabRolepermission -->
<set
name="labRolepermissions"
lazy="true"
inverse="true"
>
<key>
<column name="ROLE_ID" />
</key>
<one-to-many
class="cn.**.common.entity.LabRolepermission"
/>
</set>
<!-- bi-directional one-to-many association to LabGrouprole -->
<set
name="labGrouproles"
lazy="true"
inverse="true"
>
<key>
<column name="ROLE_ID" />
</key>
<one-to-many
class="cn.**.common.entity.LabGrouprole"
/>
</set>
</class>
</hibernate-mapping>
LabRolepermission.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cn.**.common.entity.LabRolepermission"
table="LAB_ROLEPERMISSION"
>
<composite-id name="comp_id" class="cn.**.common.entity.LabRolepermissionPK">
<!-- bi-directional many-to-one association to LabRole -->
<key-many-to-one
name="labRole"
class="cn.**.common.entity.LabRole"
>
<column name="ROLE_ID" />
</key-many-to-one>
<!-- bi-directional many-to-one association to LabPermission -->
<key-many-to-one
name="labPermission"
class="cn.**.common.entity.LabPermission"
>
<column name="PERMISSION_ID" />
</key-many-to-one>
</composite-id>
<!-- associations -->
</class>
</hibernate-mapping>
LabGroup.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cn.**.common.entity.LabGroup"
table="LAB_GROUP"
>
<id
name="groupId"
type="int"
column="GROUP_ID"
>
<generator class="sequence">
<param name="sequence">LAB_GROUP_S</param>
</generator>
</id>
<property
name="groupName"
type="java.lang.String"
column="GROUP_NAME"
length="20"
not-null="true"
/>
<property
name="groupDesc"
type="java.lang.String"
column="GROUP_DESC"
length="100"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to LabGrouprole -->
<set
name="labGrouproles"
lazy="true"
inverse="true"
>
<key>
<column name="GROUP_ID" />
</key>
<one-to-many
class="cn.**.common.entity.LabGrouprole"
/>
</set>
<!-- bi-directional one-to-many association to LabUsergroup -->
<set
name="labUsergroups"
lazy="true"
inverse="true"
>
<key>
<column name="GROUP_ID" />
</key>
<one-to-many
class="cn.**.common.entity.LabUsergroup"
/>
</set>
</class>
</hibernate-mapping>
LabUsergroup.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="cn.**.common.entity.LabUsergroup"
table="LAB_USERGROUP"
>
<composite-id name="comp_id" class="cn.**.common.entity.LabUsergroupPK">
<key-property
name="userId"
column="USER_ID"
type="java.lang.String"
length="20"
/>
<!-- bi-directional many-to-one association to LabGroup -->
<key-many-to-one
name="labGroup"
class="cn.**.common.entity.LabGroup"
>
<column name="GROUP_ID" />
</key-many-to-one>
</composite-id>
<property
name="userType"
type="int"
column="USER_TYPE"
not-null="true"
length="10"
/>
<!-- associations -->
</class>
</hibernate-mapping>
然后根据上面的数据映射文件使用hibernate-extensions工具生成实体类文件,此过程不在熬述。
(未完待续…….)