Now to the key part, where we will mix the knowledge we learned in Chapter 2, Dependency Injection Using CDI 2.0, to use persistence APIs. As you may know, any data access layer includes what's called data access objects; those objects are responsible for performing basic data housekeeping operations such as inserting, retrieving, modifying, and deleting rows from the database.
To do this in JPA, we have to first obtain an instance of the persistence provider object that implements the fundamental JPA EntityManager interface. To obtain such an object, the following code is used:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-examplesPU"); EntityManager em = emf.createEntityManager(); ...