December 2019
Intermediate to advanced
314 pages
6h 51m
English
In order to access our Customer data, we are still relying on the CustomerRepository class, which needs to be adjusted. First and foremost, we have injected an instance of the EntityManager interface in order to manage the persistence of entity instances:
@ApplicationScopedpublic class CustomerRepository { @Inject EntityManager entityManager;}
Once we have a reference to EntityManager, we can use it to perform CRUD operations on the rest of the class:
public List<Customer> findAll() { return entityManager.createNamedQuery("Customers.findAll", Customer.class) .getResultList();}public Customer findCustomerById(Long id) { Customer customer = entityManager.find(Customer.class, id); if (customer == null) { throw ...
Read now
Unlock full access