PDA

View Full Version : Error creating bean with name 'sessionFactory'



josecarlosmissias
Sep 16th, 2008, 01:54 PM
I am having problems with Spring+Equinox+Hibernate, in my bundle the following Exception occurs:




312 [SpringOsgiExtenderThread-2] ERROR org.springframework.osgi.context.support.OsgiBundl eXmlApplicationContext - Post refresh error
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in URL : Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:276)
at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:145)
at java.lang.Thread.run(Unknown Source)
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.j ava:317)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitialize r.getProxyFactory(CGLIBLazyInitializer.java:127)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.p ostInstantiate(CGLIBProxyFactory.java:43)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buil dProxyFactory(PojoEntityTuplizer.java:162)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTupli zerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
at org.hibernate.persister.entity.AbstractEntityPersi ster.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPe rsister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createCla ssPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1300)
at org.hibernate.cfg.AnnotationConfiguration.buildSes sionFactory(AnnotationConfiguration.java:859)
at org.springframework.orm.hibernate3.LocalSessionFac toryBean.newSessionFactory(LocalSessionFactoryBean .java:814)
at org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:732)
at org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:211)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1334)
... 14 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.cglib.core.ReflectUtils.defineClass(Reflect Utils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:219)
... 34 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
... 40 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClassInternal(BundleLoader.java:481)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:397)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:385)
at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 42 more



[B]I am not knowing how to correct, my configuration:

Sping DM (GA release - 1.1.1) and dependencies
Hibernate JPA (3.3.2.GA) and dependencies
Eclipse 3.4


My Bundle are organised thus:

x.y.z.domain (domain classes "Annotated Classes" :: exports)
x.y.z.domain.orm (interfaces generic DAO :: exports)
x.y.z.domain.orm.hibernate (implementation generic DAO)
- imports--> x.y.z.domain, x.y.z.domain.orm, hiberante.*, spring.*
- META-INF/sping/ applicationContext.xml (see below)
- META-INF/sping/ datasource.xml
- jdbc.properties

Spring Mapping File:




<?xml version="1.0" encoding="UTF-8"?>
...
class="org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>x.y.z.domain.Activity</value>
<value>x.y.z.domain.Company</value>

</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.bytecode.provider">javassist</prop>
</props>
</property>

</bean>
</beans>




MANIFEST.MF



Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hibernate Plug-in
Bundle-SymbolicName: x.y.z.domain.orm.hibernate
Bundle-Version: 1.0.0.M1
Bundle-Vendor: CGsys
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: br.com.cgsys.piger.domain,
br.com.cgsys.piger.domain.orm,
br.com.cgsys.piger.domain.orm.dao,
com.mysql.jdbc;version="5.1.6",
javax.persistence;version="1.0.0",
org.aopalliance.aop;version="1.0.0",
org.aopalliance.intercept;version="1.0.0",
org.apache.commons.dbcp;version="1.2.2.osgi",
org.apache.commons.logging;version="1.1.1",
org.hibernate;version="3.2.6.ga",
org.hibernate.event;version="3.2.6.ga",
org.hibernate.usertype;version="3.2.6.ga",
org.springframework.aop;version="2.5.5.A",
org.springframework.aop.support;version="2.5.5.A",
org.springframework.aop.support.annotation;version ="2.5.5.A",
org.springframework.beans.factory;version="2.5.5.A",
org.springframework.beans.factory.config;version="2.5.5.A",
org.springframework.core;version="2.5.5.A",
org.springframework.dao;version="2.5.5.A",
org.springframework.dao.annotation;version="2.5.5.A",
org.springframework.dao.support;version="2.5.5.A",
org.springframework.orm.hibernate3;version="2.5.5.A",
org.springframework.orm.hibernate3.annotation;vers ion="2.5.5.A",
org.springframework.orm.hibernate3.support;version ="2.5.5.A"
Export-Package: br.com.cgsys.piger.domain.orm.hibernate.dao

templth
Sep 16th, 2008, 02:21 PM
Hello,

I believe that you can find some informations in order to solve your error in the root cause of the exception:



Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
... 40 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClassInternal(BundleLoader.java:481)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:397)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:385)
at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 42 more


As a matter of fact, I believe that you haven't all the Import-Package in order to use Hibernate. You can try to add firstly the following one:



org.hibernate.proxy


Hope it helps you,
Thierry

josecarlosmissias
Sep 16th, 2008, 03:03 PM
Hi Thierry,

Thank you for tip but continues with the same Exception :-(

MANIFEST.MF




Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hibernate Plug-in
Bundle-SymbolicName: br.com.cgsys.piger.domain.orm.hibernate
Bundle-Version: 1.0.0.M1
Bundle-Vendor: CGsys
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: br.com.cgsys.piger.domain,
br.com.cgsys.piger.domain.orm,
br.com.cgsys.piger.domain.orm.dao,
com.mysql.jdbc;version="5.1.6",
javax.persistence;version="1.0.0",
org.aopalliance.intercept;version="1.0.0",
org.apache.commons.dbcp;version="1.2.2.osgi",
org.apache.commons.dbcp.datasources;version="1.2.2.osgi",
org.apache.commons.logging;version="1.1.1",
org.hibernate;version="3.2.6.ga",
org.hibernate.proxy;version="3.2.6.ga",
org.springframework.aop;version="2.5.5.A",
org.springframework.aop.support;version="2.5.5.A",
org.springframework.aop.support.annotation;version ="2.5.5.A",
org.springframework.beans;version="2.5.5.A",
org.springframework.core;version="2.5.5.A",
org.springframework.dao;version="2.5.5.A",
org.springframework.orm.hibernate3;version="2.5.5.A",
org.springframework.orm.hibernate3.annotation;vers ion="2.5.5.A",
org.springframework.orm.hibernate3.support;version ="2.5.5.A"
Export-Package: br.com.cgsys.piger.domain.orm.hibernate.dao

templth
Sep 17th, 2008, 02:04 AM
Hello,

Bad news! Is it the same class which is missing in the root cause of your exception? If so, it means that the bundle which gives the package, is not in an active state...

As you are using the Equinox container, can you use the ss (short status) in order to see and give us all the states of your bundles? For information, all the bundle states must be active excepted the fragment bundles which must be resolved...

Thierry

josecarlosmissias
Sep 17th, 2008, 07:36 AM
Thierry, I am novice in OSGi despite Already read very on


States of my bundles




ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE com.springsource.org.apache.commons.collections_3. 2.0
2 ACTIVE com.springsource.org.objectweb.asm_1.5.3
3 RESOLVED com.springsource.org.hibernate.ejb_3.3.2.GA
Master=38
4 ACTIVE org.eclipse.equinox.app_1.1.0.v20080421-2006
5 ACTIVE com.springsource.com.mchange.v2.c3p0_0.9.1.2
6 ACTIVE org.eclipse.core.commands_3.4.0.I20080509-2000
7 ACTIVE org.eclipse.core.resources_3.4.0.v20080604-1400
Fragments=16, 50
8 ACTIVE org.eclipse.core.expressions_3.4.0.v20080603-2000
9 ACTIVE com.springsource.org.apache.commons.dbcp_1.2.2.osg i
10 ACTIVE org.eclipse.jdt.debug_3.4.0.v20080604
11 ACTIVE com.springsource.net.sf.cglib_2.1.3
12 ACTIVE com.springsource.org.aopalliance_1.0.0
14 ACTIVE org.eclipse.equinox.common_3.4.0.v20080421-2006
15 ACTIVE org.eclipse.core.filesystem_1.2.0.v20080604-1400
Fragments=32
16 RESOLVED org.eclipse.core.resources.win32.x86_3.4.0.v200712 04
Master=7
17 ACTIVE org.springframework.bundle.osgi.io_1.1.1
18 RESOLVED com.springframework.osgi.log4j.osgi_1.0.0
Master=47
19 ACTIVE org.eclipse.equinox.registry_3.4.0.v20080516-0950
Fragments=22
20 ACTIVE org.eclipse.ant.core_3.2.0.v20080529
21 ACTIVE org.eclipse.team.core_3.4.0.I20080605
22 RESOLVED org.eclipse.core.runtime.compatibility.registry_3. 2.200.v20080610
Master=19
23 ACTIVE org.springframework.beans_2.5.5.A
24 ACTIVE org.eclipse.jdt.core_3.4.0.v_874
Fragments=40, 63
25 ACTIVE com.springsource.javax.transaction_1.1.0
26 ACTIVE org.springframework.transaction_2.5.5.A
27 ACTIVE org.eclipse.core.contenttype_3.3.0.v20080604-1400
28 ACTIVE com.springsource.org.objectweb.asm.tree.attrs_1.5. 3
29 ACTIVE org.springframework.context_2.5.5.A
30 ACTIVE com.springsource.org.hibernate.annotations.common_ 3.3.0.ga
31 ACTIVE br.com.cgsys.piger.domain_1.0.0.M1
32 RESOLVED org.eclipse.core.filesystem.win32.x86_1.1.0.v20080 604-1400
Master=15
33 ACTIVE com.springsource.org.apache.commons.logging_1.1.1
34 ACTIVE javax.servlet_2.4.0.v200806031604
35 ACTIVE org.springframework.bundle.spring.context_2.5.5
36 ACTIVE org.springframework.aop_2.5.5.A
37 ACTIVE org.eclipse.equinox.preferences_3.2.200.v20080421-2006
38 ACTIVE com.springsource.org.hibernate_3.2.6.ga
Fragments=3, 58
39 ACTIVE org.eclipse.core.jobs_3.4.0.v20080512
40 RESOLVED org.eclipse.jdt.compiler.apt_1.0.100.v20080513-1235
Master=24
41 ACTIVE org.eclipse.core.runtime_3.4.0.v20080512
42 ACTIVE com.springsource.org.apache.commons.pool_1.4.0
43 ACTIVE org.springframework.bundle.osgi.extender_1.1.1
44 ACTIVE com.springsource.antlr_2.7.7
45 ACTIVE com.springsource.javax.persistence_1.0.0
46 ACTIVE org.eclipse.text_3.4.0.v20080605-1800
47 ACTIVE org.springframework.osgi.log4j.osgi_1.2.15.SNAPSHO T
Fragments=18
48 ACTIVE com.springsource.javassist_3.3.0.ga
49 ACTIVE com.springsource.javax.xml.stream_1.0.1
50 RESOLVED org.eclipse.core.resources.compatibility_3.4.0.v20 080604-1400
Master=7
51 ACTIVE com.springsource.org.dom4j_1.6.1
52 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
53 ACTIVE br.com.cgsys.piger.domain.orm_1.0.0.M1
54 ACTIVE org.eclipse.debug.core_3.4.0.v20080612
55 ACTIVE org.eclipse.core.runtime.compatibility.auth_3.2.10 0.v20070502
56 ACTIVE com.springsource.com.mysql.jdbc_5.1.6
57 ACTIVE org.springframework.orm_2.5.5.A
58 RESOLVED com.springsource.org.hibernate.annotations_3.3.1.g a
Master=38
59 ACTIVE org.springframework.core_2.5.5.A
60 ACTIVE org.springframework.bundle.osgi.core_1.1.1
61 ACTIVE org.eclipse.core.variables_3.2.100.v20080529-1300
62 ACTIVE com.ibm.icu_3.8.1.v20080530
63 RESOLVED org.eclipse.jdt.compiler.tool_1.0.100.v_874
Master=24
64 ACTIVE org.springframework.jdbc_2.5.5.A
70 ACTIVE org.springframework.context.support_2.5.5.A
76 ACTIVE br.com.cgsys.piger.domain.orm.hibernate_1.0.0.M1

osgi>

templth
Sep 17th, 2008, 09:03 AM
Hello,

Your set of bundles seems to be consistent ;-) :
- all your bundles are in an active state
- all your fragment bundles (elements with a "master" line) are in a resolved state

So, can you give the new exception you have? Thanks.
Thierry

josecarlosmissias
Sep 17th, 2008, 09:38 AM
same exception :(

follows attached the file ".txt" with the exception and "ss command"

MANIFEST.MF of bundle "br.com.cgsys.piger.domain.orm.hibernate"




Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hibernate Plug-in
Bundle-SymbolicName: br.com.cgsys.piger.domain.orm.hibernate
Bundle-Version: 1.0.0.M1
Bundle-Vendor: CGsys
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: br.com.cgsys.piger.domain,
br.com.cgsys.piger.domain.orm,
br.com.cgsys.piger.domain.orm.dao,
com.mysql.jdbc;version="5.1.6",
javax.transaction.xa;version="1.1.0",
org.aopalliance.intercept;version="1.0.0",
org.apache.commons.dbcp;version="1.2.2.osgi",
org.apache.commons.logging;version="1.1.1",
org.hibernate;version="3.2.6.ga",
org.hibernate.property;version="3.2.6.ga",
org.hibernate.proxy;version="3.2.6.ga",
org.osgi.framework;version="1.4.0",
org.springframework.aop;version="2.5.5.A",
org.springframework.aop.support;version="2.5.5.A",
org.springframework.aop.support.annotation;version ="2.5.5.A",
org.springframework.beans;version="2.5.5.A",
org.springframework.beans.factory;version="2.5.5.A",
org.springframework.core;version="2.5.5.A",
org.springframework.dao;version="2.5.5.A",
org.springframework.dao.support;version="2.5.5.A",
org.springframework.orm;version="2.5.5.A",
org.springframework.orm.hibernate3;version="2.5.5.A",
org.springframework.orm.hibernate3.annotation;vers ion="2.5.5.A",
org.springframework.orm.hibernate3.support;version ="2.5.5.A"
Export-Package: br.com.cgsys.piger.domain.orm.hibernate.dao



ss Command






ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE com.springsource.org.apache.commons.collections_3. 2.0
2 ACTIVE com.springsource.org.objectweb.asm_1.5.3
3 RESOLVED com.springsource.org.hibernate.ejb_3.3.2.GA
Master=38
4 ACTIVE org.eclipse.equinox.app_1.1.0.v20080421-2006
5 ACTIVE com.springsource.com.mchange.v2.c3p0_0.9.1.2
6 ACTIVE org.eclipse.core.commands_3.4.0.I20080509-2000
7 ACTIVE org.eclipse.core.resources_3.4.0.v20080604-1400
Fragments=16, 50
8 ACTIVE org.eclipse.core.expressions_3.4.0.v20080603-2000
9 ACTIVE com.springsource.org.apache.commons.dbcp_1.2.2.osg i
10 ACTIVE org.eclipse.jdt.debug_3.4.0.v20080604
11 ACTIVE com.springsource.net.sf.cglib_2.1.3
12 ACTIVE com.springsource.org.aopalliance_1.0.0
14 ACTIVE org.eclipse.equinox.common_3.4.0.v20080421-2006
15 ACTIVE org.eclipse.core.filesystem_1.2.0.v20080604-1400
Fragments=32
16 RESOLVED org.eclipse.core.resources.win32.x86_3.4.0.v200712 04
Master=7
17 ACTIVE org.springframework.bundle.osgi.io_1.1.1
18 RESOLVED com.springframework.osgi.log4j.osgi_1.0.0
Master=47
19 ACTIVE org.eclipse.equinox.registry_3.4.0.v20080516-0950
Fragments=22
20 ACTIVE org.eclipse.ant.core_3.2.0.v20080529
21 ACTIVE org.eclipse.team.core_3.4.0.I20080605
22 RESOLVED org.eclipse.core.runtime.compatibility.registry_3. 2.200.v20080610
Master=19
23 ACTIVE org.springframework.beans_2.5.5.A
24 ACTIVE org.eclipse.jdt.core_3.4.0.v_874
Fragments=40, 63
25 ACTIVE com.springsource.javax.transaction_1.1.0
26 ACTIVE org.springframework.transaction_2.5.5.A
27 ACTIVE org.eclipse.core.contenttype_3.3.0.v20080604-1400
28 ACTIVE com.springsource.org.objectweb.asm.tree.attrs_1.5. 3
29 ACTIVE org.springframework.context_2.5.5.A
30 ACTIVE com.springsource.org.hibernate.annotations.common_ 3.3.0.ga
32 RESOLVED org.eclipse.core.filesystem.win32.x86_1.1.0.v20080 604-1400
Master=15
33 ACTIVE com.springsource.org.apache.commons.logging_1.1.1
34 ACTIVE javax.servlet_2.4.0.v200806031604
35 ACTIVE org.springframework.bundle.spring.context_2.5.5
36 ACTIVE org.springframework.aop_2.5.5.A
37 ACTIVE org.eclipse.equinox.preferences_3.2.200.v20080421-2006
38 ACTIVE com.springsource.org.hibernate_3.2.6.ga
Fragments=3, 58
39 ACTIVE org.eclipse.core.jobs_3.4.0.v20080512
40 RESOLVED org.eclipse.jdt.compiler.apt_1.0.100.v20080513-1235
Master=24
41 ACTIVE org.eclipse.core.runtime_3.4.0.v20080512
42 ACTIVE com.springsource.org.apache.commons.pool_1.4.0
43 ACTIVE org.springframework.bundle.osgi.extender_1.1.1
44 ACTIVE com.springsource.antlr_2.7.7
45 ACTIVE com.springsource.javax.persistence_1.0.0
46 ACTIVE org.eclipse.text_3.4.0.v20080605-1800
47 ACTIVE org.springframework.osgi.log4j.osgi_1.2.15.SNAPSHO T
Fragments=18
48 ACTIVE com.springsource.javassist_3.3.0.ga
49 ACTIVE com.springsource.javax.xml.stream_1.0.1
50 RESOLVED org.eclipse.core.resources.compatibility_3.4.0.v20 080604-1400
Master=7
51 ACTIVE com.springsource.org.dom4j_1.6.1
52 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
53 ACTIVE br.com.cgsys.piger.domain.orm_1.0.0.M1
54 ACTIVE org.eclipse.debug.core_3.4.0.v20080612
55 ACTIVE org.eclipse.core.runtime.compatibility.auth_3.2.10 0.v20070502
56 ACTIVE com.springsource.com.mysql.jdbc_5.1.6
57 ACTIVE org.springframework.orm_2.5.5.A
58 RESOLVED com.springsource.org.hibernate.annotations_3.3.1.g a
Master=38
59 ACTIVE org.springframework.core_2.5.5.A
60 ACTIVE org.springframework.bundle.osgi.core_1.1.1
61 ACTIVE org.eclipse.core.variables_3.2.100.v20080529-1300
62 ACTIVE com.ibm.icu_3.8.1.v20080530
63 RESOLVED org.eclipse.jdt.compiler.tool_1.0.100.v_874
Master=24
64 ACTIVE org.springframework.jdbc_2.5.5.A
70 ACTIVE org.springframework.context.support_2.5.5.A
80 ACTIVE br.com.cgsys.piger.domain_1.0.0.M1
82 ACTIVE br.com.cgsys.piger.domain.orm.hibernate_1.0.0.M1

osgi>

templth
Sep 17th, 2008, 10:02 AM
Really strange. Here are the list of all the packages related to Hibernate in my MANIFEST.MF file:



Import-Package:
(...)
org.hibernate;version="3.2.6.ga",
org.hibernate.classic;version="3.2.6.ga",
org.hibernate.hql;version="3.2.6.ga",
org.hibernate.hql.antlr;version="3.2.6.ga",
org.hibernate.hql.ast;version="3.2.6.ga",
org.hibernate.hql.ast.exec;version="3.2.6.ga",
org.hibernate.hql.ast.tree;version="3.2.6.ga",
org.hibernate.hql.ast.util;version="3.2.6.ga",
org.hibernate.hql.classic;version="3.2.6.ga",
org.hibernate.jdbc;version="3.2.6.ga",
org.hibernate.proxy;version="3.2.6.ga",
org.hibernate.proxy.pojo;version="3.2.6.ga",
org.hibernate.proxy.pojo.cglib;version="3.2.6.ga",
(...)


I have set too the lazy-init attribute to the definition of my LocalSessionFactoryBean bean in Spring, as follow:



<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean" lazy-init="false">
(...)
<property name="dataSource">
<osgi:reference interface="javax.sql.DataSource" timeout="5000"/>
</property>
</bean>


So, the bean is not initialize at startup but at the first call...

Moreover, I don't know how you call the service which calls Hibernate. You need to set the context-class-loader attribute with the value service-provider in order to correctly initialize the context classloader for the current thread before calling Hibernate.

Hope it helps you,
Thierry

josecarlosmissias
Sep 17th, 2008, 11:11 AM
When set lazy-init='false' the same exception is launched:



<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean" lazy-init="false">


But if I set lazy-init="true" the following exception is launched:




org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.springframework.beans.factory.config.PropertyP laceholderConfigurer] for bean with name 'propertyConfigurer' defined in URL [bundleentry://83/META-INF/spring/datasource.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer not found from bundle [br.com.cgsys.piger.domain.orm.hibernate]
at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1138)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.predictBeanType(Abstrac tAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :1174)
at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :754)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:422)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:276)
at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:145)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer not found from bundle [br.com.cgsys.piger.domain.orm.hibernate]
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findClass(BundleDelegatingClassLoader.java :103)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.loadClass(BundleDelegatingClassLoader.java :156)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.util.ClassUtils.forName(ClassU tils.java:242)
at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java:383)
at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1135)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClassInternal(BundleLoader.java:481)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:397)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:385)
at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.loadClass(BundleLoader.java:313)
at org.eclipse.osgi.framework.internal.core.BundleHos t.loadClass(BundleHost.java:227)
at org.eclipse.osgi.framework.internal.core.AbstractB undle.loadClass(AbstractBundle.java:1274)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findClass(BundleDelegatingClassLoader.java :99)
... 13 more
Exception in thread "SpringOsgiExtenderThread-2" org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.springframework.beans.factory.config.PropertyP laceholderConfigurer] for bean with name 'propertyConfigurer' defined in URL [bundleentry://83/META-INF/spring/datasource.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer not found from bundle [br.com.cgsys.piger.domain.orm.hibernate]
at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1138)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.predictBeanType(Abstrac tAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :1174)
at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :754)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:422)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
at org.springframework.osgi.context.support.AbstractD elegatedExecutionApplicationContext.completeRefres h(AbstractDelegatedExecutionApplicationContext.jav a:276)
at org.springframework.osgi.extender.internal.depende ncies.startup.DependencyWaiterApplicationContextEx ecutor$CompleteRefreshTask.run(DependencyWaiterApp licationContextExecutor.java:145)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer not found from bundle [br.com.cgsys.piger.domain.orm.hibernate]
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findClass(BundleDelegatingClassLoader.java :103)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.loadClass(BundleDelegatingClassLoader.java :156)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.util.ClassUtils.forName(ClassU tils.java:242)
at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java:383)
at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1135)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.config.PropertyP laceholderConfigurer
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClassInternal(BundleLoader.java:481)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:397)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:385)
at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:87)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.loadClass(BundleLoader.java:313)
at org.eclipse.osgi.framework.internal.core.BundleHos t.loadClass(BundleHost.java:227)
at org.eclipse.osgi.framework.internal.core.AbstractB undle.loadClass(AbstractBundle.java:1274)
at org.springframework.osgi.util.BundleDelegatingClas sLoader.findClass(BundleDelegatingClassLoader.java :99)
... 13 more


My Incitial Spring configurations:

Bundle "br.com.cgsys.piger.domain.orm.hibernate"

META-INF/spring/datasource.xml
META-INF/spring/jdbc.properties
META-INF/spring/applicationContext.xml


jdbc.properties




#MySQL datasource config.
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/piger
hibernate.dialect=org.hibernate.dialect.MySQL5Inno DBDialect
jdbc.username=user
jdbc.password=pass



datasource.xml



<?xml version="1.0" encoding="UTF-8"?>
...

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="locations">
<list>
<value>osgibundle:/jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>


applicationContext.xml




<?xml version="1.0" encoding="UTF-8"?>
...
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>br.com.cgsys.piger.domain.AbAtividade</value>
<value>br.com.cgsys.piger.domain.AbEmpresas</value>

</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.bytecode.provider">javassist</prop>
</props>
</property>

</bean>
</beans>

josecarlosmissias
Sep 17th, 2008, 11:58 AM
has something do with Launch Configurations? concerning "Start Level" and "Auto-Start" on eclipse

templth
Sep 18th, 2008, 03:21 AM
Nothing special there. I only set the start-level to 5 for the web extender bundle...
Thierry

Costin Leau
Sep 23rd, 2008, 03:24 AM
Thierry, have you considered using dm Server to get the sample working: ORM/LTW integration can be difficult to achieve properly in an OSGi environment and dm Server addresses these issues.

vanwijngaarden
Feb 6th, 2009, 03:45 PM
For the people that have problems like this, some hints:

The OSGI framework must be able to resolve the bean classes that you are loading using a spring context. So in any case, these classes must be made available in or imported by the bundle. Although maybe cumbersome, that's just the simple variant.

It gets worse when some kind of dynamic strategy is used indirectly by the beans. In that case the strategy classes must be available as well. Examples are dynamic loading of JDBC drivers, proxying strategies executed by OR mappers, etc. These indirect dependencies are not or just cannot be detected by automatic dependency tools. As a result these do not end up in the bundle dependencies of the bundles you are using.

For example: to be able to use Spring ORM in combination with Hibernate, you will need to import the Hibernate bundle explicitly. Reason: the package org.hibernate.proxy (and related) is not listed in the Spring ORM bundle as dependency (tested 2.5.6.A). This although it is needed as soon as lazy loading is somehow activated. But, since the proxying mechanism is somewhat dynamic, I expect that the dependency is not autodetected by the dependency tool.

In practice you will need to add Import-Package or Require-Bundle headers to get it working. I had to explicitly require both the hibernate and javassist bundles to get a very simple Spring ORM over hibernate example working.

fdankof
Feb 8th, 2009, 08:39 AM
Hello,

I got the exact same exception using the following setup:

- Equinox 3.4
- JBoss Hibernate 3.3.1.GA from EBR
- Springframework ORM 2.5.6.A

I would be glad if someone could give some information on how to solve this problem.

Cheers,

Fabian

vanwijngaarden
Feb 8th, 2009, 08:49 AM
Hi Fabian,

As stated above, you may need to add some additional bundle requirements in your manifest file:

Require-Bundle: com.springsource.org.hibernate,com.springsource.ja vassist

The first require solves the "proxy" class not found, the second the next problem you will get after that (loading the proxy implementing class).
Assuming that you downloaded the bundles (and their dependencies) from the SpringSource EBR.

fdankof
Feb 8th, 2009, 02:06 PM
Hi!

I declared both of them in my required-bundles list - and still got that error.
Does Equinox cache any settings so maybe it didn't take effect?

Did you use the JBoss Hibernate bundles?

jborrmann
Feb 9th, 2009, 12:30 AM
Some caching can be prevented on the settings tab of the run dialog in eclipse. You should always activate the checkbox labeled "clear the configuration area before launching". Otherwise you can have very "interesting" effects...

--- Jens

fdankof
Feb 9th, 2009, 01:22 AM
I did activate the checkbox you mentioned. Nevertheless, I still get the NoClassDefFound error. I think I have to review all my settings...

fdankof
Feb 9th, 2009, 03:27 PM
Hi!

I just solved my issue with Hibernate. Suppose the following:

- my.api Bundle (containing annotated classes)
- my.core Bundle (containing AnnotationSessionFactoryBean)

I thought I had to add the require-bundle header for org.springsource.org.hibernate and org.springsource.javassist to
the my.core plugin. BUT: Classes are contained in my.api bundle and therefore loaded by the classloader of this bundle.

Solution would be: Add require-bundle header to my.api and everything works fine.

Damn classloaders ... by the way: is there any way to find out the bundle (or: the specific classloader) that caused the
ClassNotFoundException ???

Cheers,

Fabian

Costin Leau
Feb 10th, 2009, 07:32 AM
Check the documentation of your OSGi platform and the VM switches - you could enable additional logging though normally the stracktrace gives enough hints.