You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by "Brian DePradine (JIRA)" <ji...@apache.org> on 2012/07/05 15:51:35 UTC

[jira] [Updated] (ARIES-832) JPA load-time enhamcement fails for a WAB

     [ https://issues.apache.org/jira/browse/ARIES-832?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Brian DePradine updated ARIES-832:
----------------------------------

    Attachment: latest_patch.txt

It turns out that the failure in the blog sample was due to the fact that the JPA load-time enhancement has never worked. This was not noticed due to the fact that the classes that require enhancement are enhanced at build time. This means that when the load-time enhancement failed the blog sample could just carry on without any issues.

The failure in the JPA load-time enhancement was due to the fact that it requires the org.osgi.framework.hooks.weaving.WeavingHook class to be available, which is new in OSGi 4.3. This class is not available in osgi-3.5.0.v20090520.jar as it only supports OSGi 4.2. With my changes we now explicitly check that load-time enhancement is available, otherwise we tear everything down (which is what caused the blog sample to start failing).

To fix this I have modified the blog sample to use org.eclipse.osgi-3.7.0.v20110613.jar, which supports OSGi 4.3. The setup is based on the setup used in the org.apache.aries.jpa.container.itest project.

Finally, if this patch is committed, the documentation for the blog sample at, http://aries.apache.org/modules/samples/blog-sample.html will need to be updated.
                
> 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
>         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 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