The infrastructure for the persistence layer is almost set up (only the transaction setup is missing). We can implement the repositories that will be responsible for persistence and lookup of the domain objects. Let's start with the JPACustomerRepository
interface. The JPACustomerRepository
interface uses the EntityManagerto
property to find a customer by the customerUuid
field, find customers by the first and last name, and also to add a new customer or update an existing one:
@Repository public class JPACustomerRepository implements CustomerRepository { @PersistenceContext private EntityManager em; public Customer findCustomerByUuid(String customerUuid) { return em.find(Customer.class, customerUuid); } public List<Customer> findCustomerByName(String firstName, String lastName) { return em .createQuery( "from Customer as c where c.firstName = :first" + " and c.lastName = :last") .setParameter("first...