Let's stop here for a moment. Remember our discussion of the Java Persistence API (JPA) and database? Here is where we see that coming in. With the JPA, interactions with the database are done via the EntityManager interface, which we retrieve from the cleverly named EntityManagerFactory. It is important to note that the EntityManager instances are not thread-safe, so they should not be shared between threads. That's why we didn't create one in the constructor and pass it around. This is, of course, a local variable, so we need not worry about that too much until, and if, we decide to pass it as a parameter to another method, which we are doing here. As we will see in a moment, everything happens in the same ...
Modern database access with JPA
Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.