From the course: Java Persistence with JPA

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Demo: Mapping keys

Demo: Mapping keys

- [Instructor] Let's look at real world examples of mapping a primary key. I've navigated to the employee.java file. As you're aware, one of the requirements of a relational database is that it must contain a primary key to uniquely identify a specific row in that database. Notice in our employee class, here on line 12, we have the at @Id annotation, which designates the Id field to serve as the primary key. Don't forget that the Id must be a Java primitive type or a primitive wrapper, such as integer, or long, a string, a date, big integer, or a big decimal. Here on line 13, you've learned about the @GeneratedValue annotation and the different generation strategies. In this example, we're using the strategy of GenerationType.AUTO, which means Hibernate will pick an appropriate strategy for Postgres to generate the primary key. It is also possible to combine the @Id annotation with the @Column annotation to override the…

Contents