Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-1160

Hibernate JPA: EntityManagerFactoryManager failed to create EntityManagerFactories by Bundle.RESOLVED

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.0
    • jpa-container-1.0.1
    • JPA
    • None
    • OSGi

    Description

      Use case: persistence bundle is deployed in OSGi using Hibernate persistence provider. Bundle contains blueprint configuration injecting EntityManager and activates transaction management:

      <blueprint  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
                  xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
      
        <bean id="addressDao" class="de.conrad.ccp.basit.customer.ecom.dao.impl.AddressDaoImpl"> 
            <jpa:context unitname="ecom" property="entityManager"/>
            <tx:transaction method="*" value="Required"/>
        </bean>
        
        <service ref="addressDao" interface="de.conrad.ccp.basit.entity.customer.ecom.dao.AddressDao" />
        
      </blueprint>
      

      Effect: bundle waiting for EntityManager service. The reason of problem is runtime exception by providerService.createContainerEntityManagerFactory(mpui.getPersistenceUnitInfo(), mpui.getContainerProperties()).
      Exception is unfortunately not logged by Aries. The stack trace is following:

      java.lang.IllegalStateException: The bundle de.conrad.poc.customerservice-ecom/0.0.1.SNAPSHOT is not started.
              at org.apache.aries.jpa.container.unit.impl.JndiDataSource.getDs(JndiDataSource.java:61)
              at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(DelayedLookupDataSource.java:36)
              at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
              at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
              at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
              at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
              at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
              at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
              at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1825)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1783)
              at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
              at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:99)
              at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:330)
              at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:175)
              at org.apache.aries.jpa.container.impl.PersistenceBundleManager.addingService(PersistenceBundleManager.java:197)
      

      The problem is that call of createEntityManagerFactories() in EntityManagerFactoryManager.bundleStateChange() is made by BUNDLE.RESOLVED event.
      The lookup of data source is failed, because the bundle context is not yet available (call by BUNDLE.RESOLVED event). The createEntityManagerFactory is called again by Bundle.ACTIVE event, the problem is that emfs hash map is already created, but it is empty.
      Therefore STARTED/ACTIVE createEntityManagerFactories() is called, but makes nothing.

      Attached patch contains two changes:
      a) log runtime exception throwing by providerService.createContainerEntityManagerFactory
      b) adds check to empty hash map:
      if(((emfs == null) || emfs.isEmpty()) && !quiesce)
      The patch fixes the problem.

      Basically it should analyzed is call createEntityManagerFactories() really necessary for Bundle.RESOLVED event.

      Attachments

        1. ARIES-1160-2.patch
          3 kB
          Christian Schneider
        2. aries-jpa-1.0.0-ARIES-1160.patch
          2 kB
          Christian Schneider
        3. org.apache.aries.jpa.container.patch
          1 kB
          Andrei Shakirin

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            ashakirin Andrei Shakirin
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: