aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emily Jiang (JIRA)" <>
Subject [jira] [Commented] (ARIES-832) JPA load-time enhamcement fails for a WAB
Date Wed, 11 Jul 2012 11:58:34 GMT


Emily Jiang commented on ARIES-832:

I reverted the 1st patch about creating EntityManagerFactories when a bundle is starting,
because it has caused JPA load time enhancement disfunctioning due to the entityManagerFactory
was created too late. If  creating entity manager facttories is performed when a bundle transits
to the starting state, some entity classes might have been loaded. As a consequence, they
will not be enhanced at load time. Brian will come up with a better approach towards this
issule or considering Tim's suggestion.
> JPA load-time enhamcement fails for a WAB
> -----------------------------------------
>                 Key: ARIES-832
>                 URL:
>             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
>         Attachments: PATCH2.TXT, PATCH3.TXT, latest_patch.txt, patch.txt, patch_with_test_changes.txt
> 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 is
not started.
> 	at org.apache.aries.jpa.container.unit.impl.JndiDataSource.getDs(
> 	at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(
> 	at org.apache.openjpa.lib.jdbc.DelegatingDataSource.getConnection(
> 	at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(
> 	at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(
> 	at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(
> 	at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(
> 	at org.apache.openjpa.lib.conf.Configurations.configureInstance(
> 	at org.apache.openjpa.lib.conf.Configurations.configureInstance(
> 	at org.apache.openjpa.lib.conf.PluginValue.instantiate(
> 	at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(
> 	at org.apache.openjpa.lib.conf.ObjectValue.instantiate(
> 	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(
> 	at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(
> 	at org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.<init>(
> 	at org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.<init>(
> 	at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(
> 	at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(
> 	at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(
> 	at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(
> 	at org.apache.aries.jpa.container.impl.PersistenceBundleManager.setupManager(
> 	at org.apache.aries.jpa.container.impl.PersistenceBundleManager.addingBundle(
> 	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(
> 	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(
> 	at org.osgi.util.tracker.AbstractTracked.trackAdding(
> 	at org.osgi.util.tracker.AbstractTracked.trackInitial(
> 	at
>         ...............................
> 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
>   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);
> ;
>         }
>         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:!default.jspa
For more information on JIRA, see:


View raw message