JPA相当于Hibernate的@NaturalId [英] JPA equivalent to Hibernate's @NaturalId

查看:121
本文介绍了JPA相当于Hibernate的@NaturalId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate中,我可以在实体的几个属性上使用 @NaturalId 创建一个唯一的键。



是有一个JPA等价注释,这是 javax.persistence 的一部分。

解决方案

我通常会使用 @Table(uniqueConstraints = @UniqueConstraint(columnNames = {column_1,...,column_n}))在列上添加一个唯一约束


In Hibernate I can create a unique key using @NaturalId on several properties of the entity.

Is there a JPA equivalent annotation, something that is a part of javax.persistence?

解决方案

What I usually do is add a unique constraint on the columns, using @Table(uniqueConstraints = @UniqueConstraint(columnNames={column_1, ..., column_n}))

这篇关于JPA相当于Hibernate的@NaturalId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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