hibernate unique-key和unique区别

当code 和name在数据库中不允许重复的时候加上unique="true"就行了。
<property name="code" type="string"unique="true">
          <columnname="code" length="20"/>
</property>
<property name="name"type="string">
          <columnname="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">
          <columnname="code" length="50" unique-key="base_permission_unique_key" />
</property>

<property name="name"type="string">
          <columnname="name" length="36" unique-key="base_permission_unique_key" />
</property>

http://blog.sina.com.cn/s/blog_63a3fd8f0100rldd.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值