Andrei Shakirin created ARIES-1160:
--------------------------------------

             Summary: Hibernate JPA: EntityManagerFactoryManager failed to 
create EntityManagerFactories by Bundle.RESOLVED
                 Key: ARIES-1160
                 URL: https://issues.apache.org/jira/browse/ARIES-1160
             Project: Aries
          Issue Type: Bug
          Components: JPA
    Affects Versions: 1.0
         Environment: OSGi
            Reporter: Andrei Shakirin


Use case: persistence bundle is deployed in OSGi using Hibernate persistence 
provider. Bundle contains blueprint configuration injecting EntityManager and 
activates transaction management:
<blueprint  default-activation="eager" 
            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(JndiDat
aSource.java:61)
        at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getC
onnection(DelayedLookupDataSource.java:36)
        at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.get
Connection(InjectedDataSourceConnectionProvider.java:70)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProvide
rJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer
vicesImpl.java:117)
        at org.hibernate.service.internal.StandardServiceRegistryImpl.configureS
ervice(StandardServiceRegistryImpl.java:76)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize
Service(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.jav
a:1783)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactor
yImpl.java:96)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con
figuration.java:914)
        at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManag
erFactory(OsgiPersistenceProvider.java:99)
        at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.creat
eEntityManagerFactories(EntityManagerFactoryManager.java:330)
        at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundl
eStateChange(EntityManagerFactoryManager.java:175)
        at org.apache.aries.jpa.container.impl.PersistenceBundleManager.addingSe
rvice(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. 






--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to