JPA load-time enhamcement fails for a WAB
-----------------------------------------

                 Key: ARIES-832
                 URL: https://issues.apache.org/jira/browse/ARIES-832
             Project: Aries
          Issue Type: Bug
          Components: JPA
         Environment: I am using Equinox 
org.eclipse.osgi_3.7.2.v20120110-1415.jar with Apache Aries revision 1187719 
            Reporter: Brian DePradine


I was running a test with a WAB that uses JPA, and I found that the JPA entity 
contained in the WAB was not being enhanced. The reason was due to the 
following:

187  polo  WARN   [Blueprint Extender: 1] openjpa.Runtime - An error occurred 
while registering a ClassTransformer with 
org.apache.aries.jpa.container.unit.impl.PersistenceUnitInfoImpl@69b169b1. The 
error is logged along with this warning. Load-time class transformation will 
not be available.
java.lang.IllegalStateException: The bundle 
com.ibm.osgi.jpa.warfileAdditions/1.0.0 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.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(DelegatingDataSource.java:108)
        at 
org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:87)
        at 
org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:91)
        at 
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603)
        at 
org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)
        at 
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)
        at 
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
        at 
org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
        at 
org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
        at 
org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
        at 
org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:963)
        at 
org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:954)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.<init>(PersistenceProviderImpl.java:281)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.<init>(PersistenceProviderImpl.java:265)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:168)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
        at 
org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:329)
        at 
org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:175)
        at 
org.apache.aries.jpa.container.impl.PersistenceBundleManager.setupManager(PersistenceBundleManager.java:394)
        at 
org.apache.aries.jpa.container.impl.PersistenceBundleManager.addingBundle(PersistenceBundleManager.java:154)
        at 
org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:482)
        at 
org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:1)
        at 
org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:262)
        at 
org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:185)
        at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:163)
        ...............................

It turns out that the IllegalStateException is thrown because the WAB is in the 
RESOLVED state when a request for the BundleContext is made against it. The 
javadoc says "If this bundle is not in the STARTING, ACTIVE, or STOPPING states 
or this bundle is a fragment bundle, then this bundle has no valid 
BundleContext. This method will return null if this bundle has no valid 
BundleContext."

Looking at the code in EntityManagerFactoryManager.bundleStateChange() I can 
see the following:

  public synchronized void bundleStateChange() throws 
InvalidPersistenceUnitException {
    
    switch(bundle.getState()) {
      case Bundle.RESOLVED :
        //If we are Resolved as a result of having stopped
        //and missed the STOPPING event we need to unregister
        unregisterEntityManagerFactories();
        //Create the EMF objects if necessary
        createEntityManagerFactories();
        break;
        //Starting and active both require EMFs to be registered
      case Bundle.STARTING :
      case Bundle.ACTIVE :
        if(tracker == null) {
          tracker = new ServiceTracker(bundle.getBundleContext(), 
              "org.osgi.service.jdbc.DataSourceFactory", this);
          tracker.open();
        }
        registerEntityManagerFactories();
        break;
        //Stopping means the EMFs should
      case Bundle.STOPPING :
        //If we're stopping we no longer need to be quiescing
        quiesce = false;
        if(tracker != null) {
          tracker.close();
          tracker = null;
        }
        unregisterEntityManagerFactories();
        break;
      case Bundle.INSTALLED :
        //Destroy everything
        destroyEntityManagerFactories();
    }
  }

This clearly shows that createEntityManagerFactories() gets driven when the WAB 
is in the RESOLVED state which results in the exception above. It looks like 
this should affect more than just WABs, but I have only hit this issue with 
WABs so far.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to