JPA @UniqueConstraint在Hibernate中做了什么? [英] What does JPA @UniqueConstraint do in Hibernate?

查看:122
本文介绍了JPA @UniqueConstraint在Hibernate中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate中,为什么我应该使用JPA标记:

  @Table(name =tbl_sky,
uniqueConstraints = {@UniqueConstraint(columnNames = {month,day})}

我知道何时使用它。它在数据库表的字段(元组)是唯一的时候使用。当存在复合主键时它不会被使用,因为复合主键始终是唯一的。无论如何,数据库已经实施了这种唯一约束关系,那么在我的Hibernate注释中包含这个标签有什么意义呢?如何使用这个标签帮助Hibernate?

解决方案

它有助于映射的模式生成(DDL)中的休眠。查看: http://docs.oracle.com/javaee/ 6 / api / javax / persistence / UniqueConstraint.html


In Hibernate, why should I use the JPA tag:

@Table(name="tbl_sky",
    uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
)

I know when to use it. It's used when the combination of fields (tuple) of a database table is unique. It's not used when there is a composite primary key because composite primary keys are always unique. Anyway, the database already enforces this "unique constraint" relationship, so what's the point of including this tag on my Hibernate annotations? How does using this tag help Hibernate?

解决方案

It helps hibernate in schema generation (DDL) for your mappings. Look at: http://docs.oracle.com/javaee/6/api/javax/persistence/UniqueConstraint.html

这篇关于JPA @UniqueConstraint在Hibernate中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆