[ 
http://issues.apache.org/jira/browse/OPENJPA-40?page=comments#action_12433659 ] 
            
Marc Prud'hommeaux commented on OPENJPA-40:
-------------------------------------------

This is a pretty hairy problem. The ClassCircularityError is coming from the 
fact that there are two different ClassLoaders in place: a 
org.springframework.instrument.classloading.SimpleThrowawayClassLoader, which 
is being used for temporary loading in the premain, and a 
org.springframework.instrument.classloading.SimpleInstrumentableClassLoader, 
which is being used to actually load the post-enhanced classes. The Manager and 
Client classes have a dependency on each other, and when Manager is loaded by 
SimpleThrowawayClassLoader, its metadata gets parsed, which causes Client to be 
transitively loaded. However, the XMLPersistenceMetaDataParser being used by 
our PersistenceMetaDataFactory is being configured with setClassLoader() using 
the SimpleInstrumentableClassLoader, rather than the 
SimpleThrowawayClassLoader. When Client's metadata is parsed, it then tries to 
load Manager in the SimpleInstrumentableClassLoader, which causes a re-entrant 
attempt to load Manager in SimpleThrowawayClassLoader, which is what I believe 
is causing the ClassCircularityError.

This can be fixed by changing "xmlParser.setClassLoader(loader)" to instead 
call "xmlParser.setClassLoader(envLoader)". However, if that happens, then the 
PersistenceCapable interface itself winds up getting loaded by the 
SimpleInstrumentableClassLoader, which later causes a mismatch with the 
interface with other classes (like ClassMetaData) that are loaded using the 
system AppClassLoader.

Has Spring been tested with any other JPA implementations that use bytecode 
enhancement at runtime? On one hand, OpenJPA is working fine with Glassfish, on 
the other hand, the Glassfish samples we have tested against use annotation 
mappings, rather than XML mappings, so the problem might lie there.

> Testing OpenJPA and Spring integration fails
> --------------------------------------------
>
>                 Key: OPENJPA-40
>                 URL: http://issues.apache.org/jira/browse/OPENJPA-40
>             Project: OpenJPA
>          Issue Type: Test
>         Environment:      [java] os.name: Mac OS X
>      [java] os.version: 10.4.7
>      [java] os.arch: ppc
>      [java] java.version: 1.5.0_06
>      [java] java.vendor: Apple Computer, Inc.
> OpenJPA built from SVN (revision 440460)
>            Reporter: Thomas Risberg
>         Assigned To: Marc Prud'hommeaux
>         Attachments: testOpenJpa.zip
>
>
> I have attached a test case including jar files and a build script.  
> src/repository-config.xml contains the Spring configuration and switching to 
> the TopLink vendor adapter does not show any issues - the test runs fine.  
> Using the current OpenJPA vendor adapter (Spring sandbox source is included 
> in src directory) causes this failure:
> First the version info:
> samoa:~/Projects/testOpenJpa trisberg$ ant openjpa-version
> Buildfile: build.xml
> openjpa-version:
>      [java] OpenJPA 0.9.0-incubating-SNAPSHOT
>      [java] version id: 0.9.0-incubating-SNAPSHOT-r0
>      [java] revision: 0
>      [java] os.name: Mac OS X
>      [java] os.version: 10.4.7
>      [java] os.arch: ppc
>      [java] java.version: 1.5.0_06
>      [java] java.vendor: Apple Computer, Inc.
>      [java] java.class.path:
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/commons-collections-3.2.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/commons-lang-2.1.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/commons-logging-1.0.4.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/commons-pool-1.3.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/geronimo-j2ee-connector_1.5_spec-1.0.1.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/geronimo-jta_1.0.1B_spec-1.0.1.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/hsqldb.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-jdbc-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-jdbc-5-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-kernel-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-kernel-5-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-lib-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-persistence-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-persistence-jdbc-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/openjpa-xmlstore-0.9.0-incubating-SNAPSHOT.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/persistence-api-1.0.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/serp-1.11.0.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/spring-jpa.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/spring-sandbox.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/lib/spring.jar
>      [java]     
> /Users/trisberg/Projects/testOpenJpa/lib/toplink-essentials.jar
>      [java]     /Users/trisberg/Projects/testOpenJpa/classes
>      [java]     
> /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/.compatibility/14compatibility.jar
>      [java] user.dir: /Users/trisberg/Projects/testOpenJpa
> BUILD SUCCESSFUL
> Total time: 3 seconds
> And now the runtime error:
> samoa:~/Projects/testOpenJpa trisberg$ ant run-test
> Buildfile: build.xml
> run-test:
>      [java] TestApp!
>      [java] Sep 6, 2006 1:11:02 PM org.springframework.core.CollectionFactory 
> <clinit>
>      [java] INFO: JDK 1.4+ collections available
>      [java] Sep 6, 2006 1:11:02 PM org.springframework.core.CollectionFactory 
> <clinit>
>      [java] INFO: Commons Collections 3.x available
>      [java] Sep 6, 2006 1:11:02 PM 
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader 
> loadBeanDefinitions
>      [java] INFO: Loading XML bean definitions from class path resource 
> [repository-config.xml]
>      [java] Sep 6, 2006 1:11:03 PM 
> org.springframework.context.support.AbstractRefreshableApplicationContext 
> refreshBeanFactory
>      [java] INFO: Bean factory for application context 
> [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=85537]:
>  org.springframework.beans.factory.support.DefaultListableBeanFactory 
> defining beans 
> [entityManagerFactory,transactionManager,transactionTemplate,dataSource]; 
> root of BeanFactory hierarchy
>      [java] Sep 6, 2006 1:11:03 PM 
> org.springframework.context.support.AbstractApplicationContext refresh
>      [java] INFO: 4 beans defined in application context 
> [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=85537]
>      [java] Sep 6, 2006 1:11:03 PM 
> org.springframework.context.support.AbstractApplicationContext 
> initMessageSource
>      [java] INFO: Unable to locate MessageSource with name 'messageSource': 
> using default [EMAIL PROTECTED]
>      [java] Sep 6, 2006 1:11:03 PM 
> org.springframework.context.support.AbstractApplicationContext 
> initApplicationEventMulticaster
>      [java] INFO: Unable to locate ApplicationEventMulticaster with name 
> 'applicationEventMulticaster': using default [EMAIL PROTECTED]
>      [java] Sep 6, 2006 1:11:03 PM 
> org.springframework.beans.factory.support.DefaultListableBeanFactory 
> preInstantiateSingletons
>      [java] INFO: Pre-instantiating singletons in factory 
> [org.springframework.beans.factory.support.DefaultListableBeanFactory 
> defining beans 
> [entityManagerFactory,transactionManager,transactionTemplate,dataSource]; 
> root of BeanFactory hierarchy]
>      [java] Sep 6, 2006 1:11:04 PM 
> org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
>      [java] INFO: Loaded JDBC driver: org.hsqldb.jdbcDriver
>      [java] Sep 6, 2006 1:11:04 PM 
> org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 
> createNativeEntityManagerFactory
>      [java] INFO: Allowing redeployment of EntityManagerFactory with name 
> 'main' 
>      [java] Sep 6, 2006 1:11:05 PM 
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry 
> destroySingletons
>      [java] INFO: Destroying singletons in 
> {org.springframework.beans.factory.support.DefaultListableBeanFactory 
> defining beans 
> [entityManagerFactory,transactionManager,transactionTemplate,dataSource]; 
> root of BeanFactory hierarchy}
>      [java] Exception in thread "main" 
> org.springframework.beans.factory.BeanCreationException: Error creating bean 
> with name 'entityManagerFactory' defined in class path resource 
> [repository-config.xml]: Invocation of init method failed; nested exception 
> is <4|true|0.9.0-incubating-SNAPSHOT> 
> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static 
> newInstance method on the named factory class "class 
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory".
>      [java] Caused by: <4|true|0.9.0-incubating-SNAPSHOT> 
> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static 
> newInstance method on the named factory class "class 
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory".
>      [java]     at 
> org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:71)
>      [java]     at 
> org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:84)
>      [java]     at 
> org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:262)
>      [java]     at 
> org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:227)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:957)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:924)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:415)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:242)
>      [java]     at 
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:239)
>      [java]     at 
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:155)
>      [java]     at 
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:297)
>      [java]     at 
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
>      [java]     at 
> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
>      [java]     at 
> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
>      [java]     at 
> org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
>      [java]     at springdeveloper.TestApp.run(TestApp.java:57)
>      [java]     at springdeveloper.TestApp.main(TestApp.java:31)
>      [java] Caused by: java.lang.NoSuchMethodException: 
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newInstance(org.apache.openjpa.lib.conf.ConfigurationProvider)
>      [java]     at java.lang.Class.getMethod(Class.java:1581)
>      [java]     at 
> org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62)
>      [java]     ... 17 more
> BUILD FAILED
> /Users/trisberg/Projects/testOpenJpa/build.xml:37: Java returned: 1
> Total time: 7 seconds

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to