Summary
This chapter covered how to access data in a database via the Java Persistence API (JPA).
We covered how to mark a Java class as a JPA entity by decorating it with the @Entity
annotation. Additionally, we covered how to map an entity to a database table via the @Table
annotation. We also covered how to map entity fields to database columns via the @Column
annotation, as well as declaring an entity's primary key via the @Id
annotation.
Using the javax.persistence.EntityManager
interface to find, persist, and update JPA entities was also covered.
Defining both unidirectional and bidirectional one-to-one, one-to-many, and many-to-many relationships between JPA entities was covered as well.
Additionally, we explored how to use JPA composite primary keys by developing custom primary key classes.
Also, we covered how to retrieve entities from a database by using the Java Persistence Query Language (JPQL).
We discussed additional JPA features such as the Criteria API, which allows us to build...