如何在hbm中进行多列UniqueConstraint?
处理一些遗留的休眠代码。
如何使用 hbm.xml(hibernate 映射文件)而不是注释来执行以下操作?
@Table(name="users", uniqueConstraints = {
@UniqueConstraint(columnNames={"username", "client"}),
@UniqueConstraint(columnNames={"email", "client"})
})
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private String username;
private String email;
private Client client;
}
Working on some legacy hibernate code.
How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations?
@Table(name="users", uniqueConstraints = {
@UniqueConstraint(columnNames={"username", "client"}),
@UniqueConstraint(columnNames={"email", "client"})
})
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int id;
private String username;
private String email;
private Client client;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
properties
标签:文档摘录:
所有可用选项均在 中描述Hibernate 文档。
Use the
properties
tag:Documentation extract :
All available options are described in the Hibernate documentation.
您也可以这样做:
您不需要使用 hbm 中的标签。
如果您只想要多个唯一约束。
You can also do this:
You do not need to use the tag in hbm .
If you only want multiple unique constraints.
您可以将相同的唯一键属性添加到两个不同的列。这将创建复合唯一密钥。
在上面的示例中,将从first_name 和last_name 列创建唯一键。
You can add same unique-key attribute to two different columns. This will create composite unique key.
In the above example the unique key will be created from both first_name and last_name column.