当前位置: 首页 > 面试题库 >

EclipseLinkJpaVendorAdapter而不是HibernateJpaVendorAdapter问题

邹嘉荣
2023-03-14
问题内容

使用由JSF,Spring和Hibernate组成的应用程序。我的示例正常运行,然后当我将class =“
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter”更改为class =“
org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter”时,应用程序无法正常运行。有什么问题?JPA专业化实现都是其中之一。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/jee
 http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
            http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:annotation-config />
<context:component-scan base-package="com.usta.spring" />
 <tx:annotation-driven />

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" >
    <!-- p:jpaVendorAdapter-ref="jpaAdapter"-->
  <!--  <property name="loadTimeWeaver">
       <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>     -->

    <property name="jpaVendorAdapter" ref="jpaAdapter">

    </property>
    <property name="persistenceUnitName" value="Spring_PU"/>
</bean>


<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost/spring"
        p:username="root" p:password="root" />

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

    <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true"/>
        <property name="generateDdl" value="true"/>
        <property name="database" value="MYSQL"/>
    </bean>

<!--    <bean id="jpaAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
        p:database="MYSQL" p:showSql="true" p:generateDdl="true" />    -->

<!--    <bean id="yazikontrolor" class="com.usta.spring.YaziKontolor" scope="request"/>  -->


</beans>

错误:

May 27, 2012 7:21:49 AM org.apache.catalina.core.ApplicationContext log
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'yaziServisi': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/marmara.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1073)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/marmara.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:529)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
    ... 37 more
Caused by: java.lang.IllegalStateException: Cannot apply class transformer without LoadTimeWeaver specified

问题答案:

缺省情况下,EclipseLink期望启用运行时 编织
,否则您将收到“没有指定LoadTimeWeaver不能应用类转换器”形式的错误。这意味着,对于使用构建时编织或根本不编织的情况,您将需要明确指出此行为。为了禁用EclipseLink编织,您将需要使用以下方法配置应用程序的EntityManagerFactory
Spring bean:

<property name="jpaPropertyMap">
  <map>
    <entry key="eclipselink.weaving" value="false"/>
  </map>
</property>

或添加

<property name="eclipselink.weaving" value="false"/>

到应用程序的persistence.xml文件。

我建议激活编织,因为它可以极大地提高性能。

配置EclipseLink期望的默认运行时织布工,请添加以下内容:

<property name="loadTimeWeaver">
  <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>

到应用程序的EntityManagerFactory Spring bean。

然后将此选项添加到您的JVM中:

-javaagent:/path-to-your-javaagent/org.springframework.instrument-3.1.1.RELEASE.jar

在Spring 3.x中,javaagent位于org.springframework.instrument jar中。

您需要 org.springframework.instrument 一起库 aspectjrt.jaraspectjweaver.jar
库。

参考

  • 优化JPA性能


 类似资料:
  • 问题内容: 我正在使用Spring + JPA + Hibernate开发一个网站。在持久性配置(JPA + Hibernate)中,我将HibernateJpaVendorAdapter的generateDdl属性设置为true,实际上新实体在数据库中正确创建了新表。 但是,一旦创建了表,如果我向实体添加属性,我希望HibernateJpaVendorAdapter能够更改表并添加列。这没有发生

  • 问题内容: 由于不确定的原因,我有一个旧版应用程序开始表现异常。它生成一堆HTML,由ActivePDF转换为PDF报告。 该过程如下所示: 从数据库中提取带有替换标记的HTML模板(例如,“〜CompanyName〜”,“〜CustomerName〜”等) 用真实数据替换令牌 使用简单的正则表达式函数对HTML进行整理,该函数可对HTML标签属性值进行格式设置(确保引号等,因为ActivePDF

  • 我试图在两个docker容器之间建立连接。一个是nginx服务器Symfony应用程序,另一个是Mercure。 我的应用程序工作正常,docker-comment构建也没有任何问题。问题是,当我试图测试它,并试图从Symfony应用程序发布一些东西到Mercure时,我得到了500个内部服务器错误,其中包含“未能发送更新”消息。 在堆栈跟踪中,我可以看到TransportException错误,

  • 我的第一个猜测是,这是一个数据库配置问题,但我已经确认(尽我所知),Postgres确实通过执行以下操作来接受UTF-8: 我还通过手动向数据库中插入一个条目进一步证实了这一点: 从上面可以理解,数据库已经接受了我的值,并且已经成功地将Unicode字符添加到数据库中。 我排除了应用程序的代码,因为它是一个非常大的项目的一部分,并且相关的部分在这里和那里是支离破碎的。但是,我认为它们与问题无关,因

  • 问题内容: 我正在使用postgreSQL。我有一列: 但是,当我想插入带有空字符串的行时,如下所示: 它不会给我错误并接受。如何检查插入值应为?(既不为空也不为空) PS: 我的专栏定义为: 问题答案: 向列定义添加约束。例如类似: 有关更多信息,请参见http://www.postgresql.org/docs/current/static/ddl- constraints.html

  • 问题内容: 在这个问题上,据说我可以使用访问者模式而不是一堆s。Jmg说:“如果您不能随意更改A,B和C,则可以应用访问者模式来实现相同的目的。” 据我了解,我仍然必须让A,B和C支持访问者(例如,有一种方法)。 我的问题是,我绝对不可能更改A,B和C。我只是从外国图书馆获得Car对象,而必须调用卡车,赛车和公共汽车专用的方法。 我认为我仍然需要使用s 进行构造。我对吗? 问题答案: 是的,现在要