如何为多对多连接表设置唯一的复合索引

时间:2011-10-18 11:39:27

标签: java hibernate orm mapping

我有以下映射:

  <!-- ************* Resource ************************* -->
  <class name="Resource" table="a_resource">
      <id name="resourceId">
          <column name="resource_id" />
          <generator class="identity" />
      </id>
      <property name="resourceName" type="string" not-null="true" unique="true">
          <column name="resource_name" />
      </property>
  </class>

  <!-- ************* Group ************************* -->
  <class name="Group" table="a_group">
    <id name="groupId">
      <column name="group_id"/>
      <generator class="identity"/>
    </id>
    <property name = "groupName" type="string" not-null="true" unique="true">
      <column name="group_name"/>
    </property>

    <bag name="resources" table="a_group_resource" lazy="false" >
      <key column="group_id"/>
      <many-to-many column="resource_id" class="Resource" />

    </bag>
  </class>

这会产生一个带有外键a_group_resource&amp;的联接表resource_idgroup_id

如何让hibernate在resource_id&amp;上自动创建复合唯一索引? group_id列,以便没有两个resource_id&amp; group_id组合可以存在于此连接表中吗?

0 个答案:

没有答案