Skip to content

itqpleyva/CompositePrimaryKeyJPA

Repository files navigation

CompositePrimaryKey

Example of the creation of a composite primary key using JPA

In this example,we create a composite primary key in two differents ways

  • using @IdClass
  • using @Embeddable

@IdClass

Defining the AccountId class and the attributes to be used as composite primary key

Defining the Account class, adding @IdClass(AccountId.class) and the @Id attributes(must be the same as AccountId)

@Embeddable

Defining the BookId class and the attributes to be used as composite primary key, the BookId class is annotated with @Embeddable

Defining the Book class and the bookId attribute to be used as composite primary key, the bookId attribute is annotated with @EmbeddedId

Defining the Load class to create account and book instances

About

example of composite primary key definition with JPA

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages