[
https://issues.apache.org/jira/browse/ARIES-933?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14053620#comment-14053620
]
Grzegorz Grzybek commented on ARIES-933:
----------------------------------------
Hello, Chapter _126.7.3 Caller’s Bundle Context_ of OSGi Compendium spec says
that there are three steps of getting Bundle Context:
# using property {{osgi.service.jndi.bundleContext}}
# using Thread Context Class Loader or ancestors which implements
{{BundleReference}}
# Walk the call stack until the invoker is found.
Point 3 is implemented for example
[here|https://github.com/ops4j/org.ops4j.pax.logging/blob/master/pax-logging-api/src/main/java/org/ops4j/pax/logging/internal/BundleHelper.java#L48].
IMO, because Aries JPA is rather client of Aries JNDI, it should not fail when
{{persistenceBundle.getBundleContext()}} is null.
{{org.apache.aries.jpa.container.unit.impl.JndiDataSource#getDs()}} should
rather try to look the DS using no-arg {{new InitialContext()}} and let Aries
JNDI worry about finding the bundle Class Loader.
> IllegalStateException when the peristence bundle gets resolved.
> ---------------------------------------------------------------
>
> Key: ARIES-933
> URL: https://issues.apache.org/jira/browse/ARIES-933
> Project: Aries
> Issue Type: Bug
> Components: JPA
> Affects Versions: 0.3, 1.0
> Reporter: Ioannis Canellos
> Attachments: ARIES-933.patch
>
>
> Aries JPA tries to create the entity manager factories when the persistence
> bundle gets in resolved state.
> With some persistence providers this can cause issues. For example Hibernate
> will try to access the datasource via jndi when creating the EMF, causing the
> IllegalStateException due to the fact that the persistnce bundle still has
> not context (is in resolved state).
> Even worse it will leave the EntityManagerFactoryManager is a wrong state,
> preventing it to create the EMF when the bundle is created.
> There are two ways of approaching this issue:
> i) Don't try to create EMF when the persistence bundle gets resolved.
> ii) Catch possible errors and cleanup, so that EMF can be created when the
> bundle gets started.
> I am going to attach a patch for the first appraoch, unless there is a good
> way for creating EMF when the bundle gets resolved.
--
This message was sent by Atlassian JIRA
(v6.2#6252)