Class JPAService

  • Direct Known Subclasses:
    JPAAuditLogService

    public class JPAService
    extends Object

    The idea here is that we have a entity manager factory (similar to a session factory) that we repeatedly use to generate an entity manager (which is a persistence context) for the specific service command.

    To start with, not all of our entities contain LOB's ("Large Objects" see https://en.wikibooks.org/wiki/Java_Persistence/Basic_Attributes#LOBs.2C_BLOBs .2C_CLOBs_and_Serialization) which sometimes necessitate the use of tx's even in read situations.

    However, we use transactions here none-the-less, just to be safe. Obviously, if there is already a running transaction present, we don't do anything to it.

    At the end of every command or operation, make sure to close the entity manager you've been using -- which also means that you should detach any entities that might be associated with the entity manager/persistence context.

    After all, this is a service which means our philosophy here is to provide a real interface, and not a leaky absraction. (https://en.wikipedia.org/wiki/Leaky_abstraction)
    • Field Detail

      • persistenceUnitName

        protected String persistenceUnitName
    • Constructor Detail

      • JPAService

        public JPAService​(String persistenceUnitName)
      • JPAService

        public JPAService​(org.kie.api.runtime.Environment env,
                          String persistenceUnitName)
      • JPAService

        public JPAService​(javax.persistence.EntityManagerFactory emf)
    • Method Detail

      • setPersistenceUnitName

        public void setPersistenceUnitName​(String persistenceUnitName)
      • getPersistenceUnitName

        public String getPersistenceUnitName()
      • dispose

        public void dispose()
      • getEntityManager

        protected javax.persistence.EntityManager getEntityManager()
      • joinTransaction

        protected Object joinTransaction​(javax.persistence.EntityManager em)
      • closeEntityManager

        protected void closeEntityManager​(javax.persistence.EntityManager em,
                                          Object transaction)
      • executeQuery

        public <T> List<T> executeQuery​(javax.persistence.Query query,
                                        javax.persistence.EntityManager em,
                                        Class<T> type)