如何为多对多连接表设置唯一复合索引
我有以下映射:
<!-- ************* 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>
这会产生一个带有外键 resource_id
的连接表 a_group_resource
。 group_id
。
如何让 hibernate 自动在 resource_id
上创建复合唯一索引? group_id
列,以便没有两个resource_id & group_id组合可以存在于这个连接表中吗?
I have the following mappings:
<!-- ************* 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>
This results in a join-table a_group_resource
with foreign keys resource_id
& group_id
.
How can I make hibernate to automatically create a composite unique index on resource_id
& group_id
columns so that no two resource_id & group_id combinations can exist in this join table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论