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 - Java Tutorial
From the course: Java Persistence with JPA
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
What is an entity?4m 3s
-
(Locked)
Demo: Working with the entity manager4m 50s
-
(Locked)
Demo: Persisting entities3m 53s
-
(Locked)
Mapping keys3m 1s
-
(Locked)
Demo: Mapping keys1m 54s
-
(Locked)
Implementing CRUD operations2m 49s
-
(Locked)
Demo: CRUD operations2m 10s
-
(Locked)
Challenge: Persist employee, company, and salary entities2m 17s
-
(Locked)
Solution: Persist employee, company, and salary entities3m 55s
-
-
-
-
-