Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA equivalent to Hibernate's @NaturalId

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?

like image 440
Ido Barash Avatar asked Jan 10 '13 09:01

Ido Barash


People also ask

What is @NaturalId JPA?

Just like with the JPA @Id annotation, the @NaturalId allows you to fetch the entity if you know the associated natural key.

Is @column mandatory in JPA?

Let's start with the @Column annotation. It is an optional annotation that enables you to customize the mapping between the entity attribute and the database column.

Is JPA and Spring Data JPA same?

Speaking precisely, Spring Data JPA is an add-on for JPA. It provides a framework that works with JPA and provides a complete abstraction over the Data Access Layer. Spring Data JPA brings in the concept of JPA Repositories, a set of Interfaces that defines query methods.

Can we use JPA without ORM?

you can't use JPA on its own. JPA is a specification, which defines an API for object-relational mappings and for managing persistent objects and you need a JPA provider to implement it, like Hibernate, EclipseLink. Save this answer.


1 Answers

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

like image 192
Johanneke Avatar answered Sep 28 '22 12:09

Johanneke