<hibernate-mapping package="org.hyperic.hq.authz.server.session">
<class name="Resource" table="EAM_RESOURCE" lazy="true">
<!-- 缓存usage(必须)说明了缓存的策略 -->
<cache usage="read-write"/>
<!-- name指类中的变量 -->
<id name="id" type="integer">
<!-- column指表中的字段 -->
<column name="ID" not-null="true"/>
<!-- generator是一个生成器,用来为id分配值 -->
<generator class="org.hyperic.hibernate.id.ComboGenerator">
<param name="sequence">EAM_RESOURCE_ID_SEQ</param>
</generator>
或者是
<generator class="identity"></generator>
</id>
<!-- 实现乐观锁要在表中添加版本控制字段 乐观锁就是跟事务有关
比如:两个事务的提交,第二个比第一个提交的版本旧就会报异常
-->
<version name="_version_" type="long">
<column name="VERSION_COL" default="0"/>
</version>
<!-- 在数据库表中有体现,多对一,外键,对应ResourceType表
一对多在类中的类型就是对应的类
-->
<many-to-one name="resourceType" class="ResourceType">
<column name="RESOURCE_TYPE_ID" not-null="false"/>
</many-to-one>
<property name="instanceId" type="integer">
<!-- index是索引字段 -->
<column name="INSTANCE_ID" not-null="false" index="EAM_RESOURCE_INSTANCE_ID_IDX"/>
</property>
<many-to-one name="owner" class="AuthzSubject">
<column name="SUBJECT_ID" not-null="false" index="EAM_RESOURCE_OWNER_ID_IDX"/>
</many-to-one>
<many-to-one name="prototype">
<column name="PROTO_ID" not-null="true" index="EAM_RESOURCE_PROTO_IDX"/>
</many-to-one>
<property name="name" type="string">
<column name="NAME" not-null="false" length="500"/>
</property>
<property name="sortName" type="string">
<column name="SORT_NAME" not-null="false" length="500"/>
</property>
<property name="system" type="boolean">
<column name="FSYSTEM" not-null="false"/>
</property>
<property name="mtime" type="long">
<column name="MTIME" default="0"/>
</property>
<!-- 集合映射
name为resource类中的变量
EAM_RES_GRP_RES_MAP为映射的表
key为EAM_RES_GRP_RES_MAP表中的RESOURCE_ID字段对应resource的id
-->
<bag inverse="true" cascade="all-delete-orphan" name="groupBag" table="EAM_RES_GRP_RES_MAP">
<cache usage="read-write"/>
<key column="RESOURCE_ID"/>
<one-to-many class="GroupMember"/>
</bag>
<bag inverse="true" cascade="all-delete-orphan" name="virtuals" table="EAM_VIRTUAL">
<key on-delete="cascade" column="RESOURCE_ID"/>
<one-to-many class="Virtual"/>
</bag>
<!-- We primarily only want this bag so that Hibernate can use HQL joins
for us. It should not be used from code -->
<bag inverse="true" cascade="none" name="fromEdges" table="EAM_RESOURCE_EDGE">
<key on-delete="cascade" column="FROM_ID"/>
<one-to-many class="ResourceEdge"/>
</bag>
<bag inverse="true" cascade="none" name="toEdges" table="EAM_RESOURCE_EDGE">
<key on-delete="cascade" column="TO_ID"/>
<one-to-many class="ResourceEdge"/>
</bag>
</class>
</hibernate-mapping>