如果没有指定LoadTimeWeaver,则无法应用类转换器

时间:2014-11-20 04:45:48

标签: java spring tomcat jpa openjpa

有一个带有实体和daos(openjpa)的jar模块和一个web模块,它通过spring连接到控制器。 jar模块中的测试运行正常,但在尝试在Web模块中使用daos时,出现此错误:

[2014-11-20 15:12:00,692] - openjpa.Runtime An error occurred while registering a ClassTransformer with PersistenceUnitInfo: name 'analytics-persistence-unit', root URL [file:/C:/work/tools/tomcat/webapps/events/WEB-INF/lib/analytics-1.0-SNAPSHOT.jar]. The error is logged along with this warning. Load-time class transformation will not be available. 
java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy13.addTransformer(Unknown Source)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:168)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.qbe.asia.ebusiness.system.event.EbizEventObserver.<init>(EbizEventObserver.java:38)
    at com.qbe.asia.ebusiness.system.event.ServletContextListenerImpl.contextInitialized(ServletContextListenerImpl.java:23)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1654)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager$Jpa2PersistenceUnitInfoDecorator.invoke(DefaultPersistenceUnitManager.java:617)
    ... 34 more
Caused by: java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
    at org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:109)

持久性单元看起来像这样:

<persistence-unit name="analytics-persistence-unit" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<!--non-jta-data-source>analyticsDS</non-jta-data-source-->
<properties>
    <property name="openjpa.ConnectionUserName" value="SA"/>
    <property name="openjpa.ConnectionPassword" value=""/>
    <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:file:~/hsqldb/reports"/>
    <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/>

    <property name="openjpa.DynamicEnhancementAgent" value="false"/>
    <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
    <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
    <property name="openjpa.Log" value="log4j"/>
    <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
</properties>

在构建时,openjpa-maven-plugin会增强功能。

Web模块基于jar模块的持久性单元加载实体管理器:

<bean id="analytics-em-factory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="analytics-persistence-unit" />
    <property name="packagesToScan" value="com.qbe.asia.analytics.model" />
</bean>

问题是,我真的不明白错误。 Google从2007年开始返回与eclipse Link相关的帖子,这些帖子并没有多大帮助。

对我的问题究竟是什么的任何解释?

1 个答案:

答案 0 :(得分:0)

问题是OpenJPA尝试使用Spring注册ClassTransformer,无论出于何种原因,对于这种情况都不会有效。你没有提到你正在使用的OpenJPA版本,但我有点记得看到OpenJPA吞下这个例外的变化,因为如果使用构建时间增强它是良性的。