数据库中值不能重复之hibernate配置
当code 和name在数据库中不允许重复的时候 加上unique="true"就行了。
<property name="code" type="string" unique="true">
<column name="code" length="20"/>
</property>
<property name="name" type="string">
<column name="name" length="50" unique="true"/>
</property>
还有一种情况:
如果:数据库中有信息:code=“1” name=“2”,现在要插入code="1" name ="3"
如果是上面的配置的话肯定会报出code不能重复,
此时就需要将code和name设置相同的:unique-key=" "这样在插入数据的时候就会判断 除非插入的数据相同的code对应的name也相同的话才会报框
<property name="code" type="string">
<column name="code" length="50" unique-key="base_permission_unique_key"/>
</property>
<property name="name" type="string">
<column name="name" length="36" unique-key="base_permission_unique_key"/>
</property>
posted on 2018-04-14 15:14 Jesseylove 阅读(978) 评论(0) 编辑 收藏 举报