O'Reilly logo

JBoss Weld CDI for Java Platform by Ken Finnigan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating CDI services

In creating the services that interact with JPA, we decided to abstract some methods out into a parent service that all our services can inherit. It wasn't necessary to develop it in this way, as it is all down to personal preference in the end.

  1. Our parent service will inject an EntityManager for JPA calls, and will take advantage of Java Generics to provide some common methods for retrieving an entity by an identifier and retrieving all instances of an entity type:
    public abstract class AbstractService<T> { @Inject @BookDB private EntityManager entityManager; private Class<T> entityClass; public AbstractService() {} public AbstractService(Class<T> entityClass) { this.entityClass = entityClass; } protected EntityManager getEntityManager() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required