Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320454

Summary: Failed to wire optional package, while another optional (sub)package is wired
Product: [Eclipse Project] Equinox Reporter: Wolfgang Schell <ws>
Component: FrameworkAssignee: equinox.framework-inbox <equinox.framework-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: tjwatson
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: stalebug
Attachments:
Description Flags
Project containing target platform definition and launch configuration
none
Manifest of bundle com.springsource.org.hibernate
none
Manifest of bundle org.springframework.orm none

Description Wolfgang Schell CLA 2010-07-20 20:49:42 EDT
Build Identifier: 3.5.1.R35x_v20090827, R-3.6-201006080911

I'm working on an OSGi plugin for Grails, which uses using Spring and Hibernate. Grails tries to create a Hibernate session with a HibernateTransactionManager, which fails with a NoClassDefFoundException: org.hibernate.cache.CacheProvider, because the Spring ORM bundle doesn't see package org.hibernate.cache, which is provided by the Hibernate bundle from EBR.

I'm using bundles org.springframework.orm (tried 3.0.3.RELEASE and 3.0.1.RELEASE-A) and com.springsource.org.hibernate (3.3.2.GA) from SpringSource Enterprise Bundle Repository (EBR) with Equinox 3.5.1 and 3.6.0. When running with Equinox's trace option org.eclipse.osgi/resolver/wiring = true, the following statement can be seen in the OSGi console:

...
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.cfg -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate.cfg
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.cache.access -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate.cache.access
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.cache -> OPTIONAL (could not be wired)
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.annotations -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate.annotations
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate
...

Please note the part org.hibernate.cache -> OPTIONAL (could not be wired).

I first reported the issue in the Spring JIRA (SPR-7003: http://jira.springframework.org/browse/SPR-7003), but there does not seem to be an error. 
Costin Leau of SpringSource said, it works, if the dependency is changed to mandatory (see http://jira.springframework.org/browse/SPR-7003?focusedCommentId=52323#action_52323), which in my opinion rules out missing uses-constraints. 


After start up, the OSGi console prints many log messages, because of wiring trace options. When everything has settled down, the bundle list may be obtain with the command ss, which produces the list of bundles as seen below..
When refreshing the Spring ORM bundle (which has id 18 in the example below), the wiring message above can be seen on the console:

osgi> refresh 18

Framework is launched.

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.6.0.v20100517
1	ACTIVE      com.springsource.org.dom4j_1.6.1
2	ACTIVE      com.springsource.org.apache.commons.validator_1.3.1
3	ACTIVE      com.springsource.net.sf.cglib_2.2.0
4	ACTIVE      com.springsource.org.apache.oro_2.0.8
5	ACTIVE      com.springsource.org.apache.ivy_2.0.0
6	ACTIVE      com.springsource.javax.servlet.jsp_2.1.0
7	ACTIVE      org.springframework.asm_3.0.3.RELEASE
8	ACTIVE      org.eclipse.osgi.services_3.2.100.v20100503
9	ACTIVE      org.springframework.oxm_3.0.3.RELEASE
10	ACTIVE      org.eclipse.osgi.util_3.2.100.v20100503
11	ACTIVE      com.springsource.javax.servlet_2.5.0
12	ACTIVE      com.springsource.javax.transaction_1.1.0
13	ACTIVE      com.springsource.org.apache.xalan_2.7.1
14	ACTIVE      com.springsource.org.hibernate_3.3.2.GA
	            Fragments=33, 59
15	ACTIVE      com.springsource.net.sf.ehcache_1.6.2
16	ACTIVE      com.springsource.org.objectweb.asm_1.5.3
17	ACTIVE      org.ops4j.pax.logging.pax-logging-service_1.5.2
18	ACTIVE      org.springframework.orm_3.0.3.RELEASE
19	ACTIVE      com.springsource.org.jgroups_2.5.1
20	ACTIVE      com.springsource.org.xmlpull_1.1.4.c
21	ACTIVE      com.springsource.org.apache.xmlcommons_1.3.4
	            Fragments=29
22	ACTIVE      com.springsource.org.jboss.cache_3.2.0.GA
23	ACTIVE      com.springsource.javax.mail_1.4.1
24	ACTIVE      com.springsource.org.apache.commons.el_1.0.0
25	ACTIVE      com.springsource.javax.xml.rpc_1.1.0
26	ACTIVE      com.springsource.org.apache.xml.resolver_1.2.0
27	ACTIVE      com.springsource.javax.el_1.0.0
28	ACTIVE      com.springsource.org.jboss.logging_2.0.5.GA
29	RESOLVED    com.springsource.org.apache.xerces_2.9.1
	            Master=21
30	ACTIVE      com.springsource.org.aopalliance_1.0.0
31	ACTIVE      org.springframework.transaction_3.0.3.RELEASE
32	ACTIVE      org.springframework.core_3.0.3.RELEASE
33	RESOLVED    com.springsource.org.hibernate.cache_3.3.2.GA
	            Master=14
34	ACTIVE      com.springsource.org.apache.commons.collections_3.2.1
35	ACTIVE      com.springsource.org.apache.commons.httpclient_3.1.0
36	ACTIVE      com.springsource.org.apache.tools.ant_1.7.1
37	ACTIVE      com.springsource.javax.annotation_1.0.0
38	ACTIVE      org.ops4j.pax.logging.pax-logging-api_1.5.2
39	ACTIVE      com.springsource.org.apache.xml.serializer_2.7.1
40	ACTIVE      com.springsource.org.apache.xml.security_1.4.2
41	ACTIVE      com.springsource.javax.persistence_1.99.0
42	ACTIVE      com.springsource.org.apache.commons.lang_2.4.0
43	ACTIVE      org.springframework.jdbc_3.0.3.RELEASE
44	ACTIVE      org.springframework.aspects_3.0.3.RELEASE
45	ACTIVE      org.eclipse.equinox.common_3.6.0.v20100503
46	ACTIVE      com.springsource.org.hibernate.annotations.common_3.3.0.ga
47	ACTIVE      com.springsource.org.apache.commons.beanutils_1.8.0
48	ACTIVE      com.springsource.org.apache.commons.dbcp_1.2.2.osgi
49	ACTIVE      com.springsource.antlr_2.7.7
50	ACTIVE      com.springsource.org.apache.commons.fileupload_1.2.1
51	ACTIVE      org.springframework.aop_3.0.3.RELEASE
52	ACTIVE      org.springframework.beans_3.0.3.RELEASE
53	ACTIVE      org.springframework.web_3.0.3.RELEASE
54	ACTIVE      com.springsource.javassist_3.9.0.GA
55	ACTIVE      com.springsource.org.apache.commons.digester_1.8.1
56	ACTIVE      com.springsource.org.apache.commons.pool_1.5.3
57	ACTIVE      org.springframework.context.support_3.0.3.RELEASE
58	ACTIVE      com.springsource.javax.ejb_3.0.0
59	RESOLVED    com.springsource.org.hibernate.annotations_3.4.0.GA
	            Master=14
60	ACTIVE      com.springsource.org.apache.log4j_1.2.15
61	ACTIVE      org.springframework.expression_3.0.3.RELEASE
62	ACTIVE      com.springsource.org.apache.commons.io_1.4.0
63	ACTIVE      org.springframework.context_3.0.3.RELEASE
64	ACTIVE      com.springsource.org.apache.commons.codec_1.3.0
65	ACTIVE      com.springsource.org.jboss.util_2.2.13.GA
66	ACTIVE      org.springframework.web.servlet_3.0.3.RELEASE

[snip]
		...
		(w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.cache.access -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate.cache.access
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.cache -> OPTIONAL (could not be wired)
        (w) [org.springframework.orm_3.0.3.RELEASE]:org.hibernate.annotations -> [com.springsource.org.hibernate_3.3.2.GA]:org.hibernate.annotations
        ...
[snip]





Reproducible: Always

Steps to Reproduce:
================================================================
How to reproduce (Eclipse target platform + launch configuration)
================================================================


1. Please download the attached project hibcache-test-equinox.zip and extract it into your workspace. This creates the project hibcache-test-equinox.

2. In order to run the configuration within Eclipse, the required bundles must be downloaded from the Internet (I didn't attach binary bundles for the sake of disk space).
Get Ivy:
Download the zipped package from http://ant.apache.org/ivy/download.cgi
or the jar directly from http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/ivy/ivy/2.1.0/ivy-2.1.0.jar
We need only ivy-2.1.0.jar in the root of the project

3. Resolve all required bundles

On Linux or OSX run getbundles.sh or 

java -jar ivy-2.1.0.jar -settings ivysettings.xml -ivy ivy-bundles.xml

or on Windows run getbundles.bat or

java -jar ivy-2.1.0.jar -settings ivysettings.xml -ivy ivy-bundles.xml


When a HTTP proxy is required:

On Linux or OSX execute 

export JAVA_OPTS="-Dhttp.proxyHost=myHost -Dhttp.proxyPort=8080"

or on Windows execute 

set JAVA_OPTS="-Dhttp.proxyHost=myHost -Dhttp.proxyPort=8080"

in the same shell, which will be used with ivy.


This may take some time to download all required bundles from Maven repos (mostly from EBR).
The downloaded bundles will be stored in directory "system/bundles"


4. After downloading required bundles, the project should be refreshed and the target platform definition Hibcache-test-equinox.target can be opened.
The Target Definition editor should show 68 plugins. Please activate this target platform by clicking on "Set as Target Platform" on the upper right of the editor.

5. Open the launch configuration hibcache-test-equinox.launch and run/debug it. The console will show the OSGi prompt.

Look up bundle id of Spring ORM bundle and refresh it. The mentioned trace message is printed on the console.
Comment 1 Wolfgang Schell CLA 2010-07-20 20:51:29 EDT
Created attachment 174810 [details]
Project containing target platform definition and launch configuration
Comment 2 Thomas Watson CLA 2010-07-21 09:34:34 EDT
The uses directive is involved here.  The resolver finds the first solution that has no conflicts, if an optional constraint introduces a conflict the framework is free to drop the optional constraint if the result is a consistent class space.  I am confused why org.springframework.orm has an optional import that does not really seem optional.  It will fail if the package is not wired which seems to indicate it is not optional.

If you switch the constraint to not be mandatory then you force the framework to wire the import and find another solution that is not in conflict with the mandatory import.
Comment 3 Wolfgang Schell CLA 2010-07-21 10:21:33 EDT
The Spring ORM provides ORM solutions for different providers, such as Hibernate, EclipseLink, etc. In order to support all of them but don't depend on all of them at the same time, the dependencies are optional.

How do I diagnose, which constraints create conflicts, so that I can change or work around them?

I also tried to use a fragment, which imported org.hibernate.cache without setting it to optional, but that didn't work. Maybe the first import statement (which is from the Host bundle and has optional:=true) wins?

Is there some other way to force this import as mandatory?
Comment 4 Wolfgang Schell CLA 2010-07-26 18:49:46 EDT
Created attachment 175280 [details]
Manifest of bundle com.springsource.org.hibernate
Comment 5 Wolfgang Schell CLA 2010-07-26 18:50:14 EDT
Created attachment 175281 [details]
Manifest of bundle org.springframework.orm
Comment 6 Wolfgang Schell CLA 2010-07-26 18:51:21 EDT
I attached the manifest (re-formatted for better readability) of the two bundles.

Any hints regarding uses-clause or other diagnosis?

Many thanks in advance!
Comment 7 Wolfgang Schell CLA 2010-08-19 11:06:40 EDT
I'm still not able to get the Spring ORM bundle to resolve with these optional imports. Might this be a case similar to bug 316414, where the Exquinox resolver gives up after a timeout?

Any hints on how to debug this? Which tracing options show more information?

Many thanks for your help!
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:09:49 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 9 Eclipse Genie CLA 2021-09-05 14:22:10 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.