spring springdata jpa 报错

本文记录了在Spring4.2.6环境中,使用SpringData JPA和Hibernate进行集成测试时遇到的NoSuchMethodError异常,具体为PersistenceUnitInfo.getValidationMode()方法未找到的问题。通过分析错误堆栈,发现此问题是由于Hibernate版本与JPA规范版本不匹配导致。
摘要由CSDN通过智能技术生成
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63799,suspend=y,server=n -ea -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/tools.jar:/Users/zhaoguoxin/Java/IDEA/gxspringdata/jpa/target/test-classes:/Users/zhaoguoxin/Java/IDEA/gxspringdata/jpa/target/classes:/Users/zhaoguoxin/devtools/repo/org/springframework/data/spring-data-jpa/1.10.2.RELEASE/spring-data-jpa-1.10.2.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/data/spring-data-commons/1.12.2.RELEASE/spring-data-commons-1.12.2.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-core/4.2.6.RELEASE/spring-core-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-beans/4.2.6.RELEASE/spring-beans-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/slf4j/slf4j-api/1.7.21/slf4j-api-1.7.21.jar:/Users/zhaoguoxin/devtools/repo/org/slf4j/jcl-over-slf4j/1.7.21/jcl-over-slf4j-1.7.21.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-orm/4.2.6.RELEASE/spring-orm-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-jdbc/4.2.6.RELEASE/spring-jdbc-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-tx/4.2.6.RELEASE/spring-tx-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-context/4.2.6.RELEASE/spring-context-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-aop/4.2.6.RELEASE/spring-aop-4.2.6.RELEASE.jar:/Users/zhaoguoxin/devtools/repo/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/Users/zhaoguoxin/devtools/repo/org/aspectj/aspectjrt/1.8.9/aspectjrt-1.8.9.jar:/Users/zhaoguoxin/devtools/repo/org/apache/commons/commons-dbcp2/2.1.1/commons-dbcp2-2.1.1.jar:/Users/zhaoguoxin/devtools/repo/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar:/Users/zhaoguoxin/devtools/repo/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/zhaoguoxin/devtools/repo/mysql/mysql-connector-java/6.0.3/mysql-connector-java-6.0.3.jar:/Users/zhaoguoxin/devtools/repo/javax/persistence/persistence-api/1.0.2/persistence-api-1.0.2.jar:/Users/zhaoguoxin/devtools/repo/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar:/Users/zhaoguoxin/devtools/repo/org/hibernate/hibernate-core/5.2.1.Final/hibernate-core-5.2.1.Final.jar:/Users/zhaoguoxin/devtools/repo/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar:/Users/zhaoguoxin/devtools/repo/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar:/Users/zhaoguoxin/devtools/repo/org/javassist/javassist/3.20.0-GA/javassist-3.20.0-GA.jar:/Users/zhaoguoxin/devtools/repo/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/zhaoguoxin/devtools/repo/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.1.1/geronimo-jta_1.1_spec-1.1.1.jar:/Users/zhaoguoxin/devtools/repo/org/jboss/jandex/2.0.0.Final/jandex-2.0.0.Final.jar:/Users/zhaoguoxin/devtools/repo/com/fasterxml/classmate/1.3.0/classmate-1.3.0.jar:/Users/zhaoguoxin/devtools/repo/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/Users/zhaoguoxin/devtools/repo/org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1.Final.jar:/Users/zhaoguoxin/devtools/repo/javax/enterprise/cdi-api/1.1-PFD/cdi-api-1.1-PFD.jar:/Users/zhaoguoxin/devtools/repo/javax/el/el-api/2.2/el-api-2.2.jar:/Users/zhaoguoxin/devtools/repo/org/jboss/spec/javax/interceptor/jboss-interceptors-api_1.1_spec/1.0.0.Beta1/jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar:/Users/zhaoguoxin/devtools/repo/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar:/Users/zhaoguoxin/devtools/repo/javax/inject/javax.inject/1/javax.inject-1.jar:/Users/zhaoguoxin/devtools/repo/junit/junit/4.12/junit-4.12.jar:/Users/zhaoguoxin/devtools/repo/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/zhaoguoxin/devtools/repo/org/springframework/spring-expression/4.2.6.RELEASE/spring-expression-4.2.6.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.github.gx.springdata.jpa.repository.UserRepositoryTest,testDataSource
Connected to the target VM, address: '127.0.0.1:63799', transport: 'socket'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
七月 09, 2016 1:35:47 上午 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
	name: default
	...]
七月 09, 2016 1:35:47 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.1.Final}
七月 09, 2016 1:35:47 上午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
七月 09, 2016 1:35:47 上午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at com.github.gx.springdata.jpa.repository.UserRepositoryTest.<init>(UserRepositoryTest.java:24)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
	at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:88)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.mergeSettings(EntityManagerFactoryBuilderImpl.java:444)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:198)
	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:162)
	at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54)
	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
	... 33 more

Disconnected from the target VM, address: '127.0.0.1:63799', transport: 'socket'

Process finished with exit code 255

项目时spring 4.2.6

< 1.8 > Maven: antlr:antlr:2.7.7 Maven: aopalliance:aopalliance:1.0 Maven: com.fasterxml:classmate:1.3.0 Maven: commons-logging:commons-logging:1.2 Maven: dom4j:dom4j:1.6.1 Maven: javax.annotation:jsr250-api:1.0 Maven: javax.el:el-api:2.2 Maven: javax.enterprise:cdi-api:1.1-PFD Maven: javax.inject:javax.inject:1 Maven: javax.persistence:persistence-api:1.0.2 Maven: junit:junit:4.12 Maven: mysql:mysql-connector-java:6.0.3 Maven: org.apache.commons:commons-dbcp2:2.1.1 Maven: org.apache.commons:commons-pool2:2.4.2 Maven: org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1 Maven: org.aspectj:aspectjrt:1.8.9 Maven: org.hamcrest:hamcrest-core:1.3 Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final Maven: org.hibernate:hibernate-core:5.2.1.Final Maven: org.javassist:javassist:3.20.0-GA Maven: org.jboss.logging:jboss-logging:3.3.0.Final Maven: org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:1.0.0.Beta1 Maven: org.jboss:jandex:2.0.0.Final Maven: org.slf4j:jcl-over-slf4j:1.7.21 Maven: org.slf4j:slf4j-api:1.7.21 Maven: org.springframework.data:spring-data-commons:1.12.2.RELEASE Maven: org.springframework.data:spring-data-jpa:1.10.2.RELEASE Maven: org.springframework:spring-aop:4.2.6.RELEASE Maven: org.springframework:spring-beans:4.2.6.RELEASE Maven: org.springframework:spring-context:4.2.6.RELEASE Maven: org.springframework:spring-core:4.2.6.RELEASE Maven: org.springframework:spring-expression:4.2.6.RELEASE Maven: org.springframework:spring-jdbc:4.2.6.RELEASE Maven: org.springframework:spring-orm:4.2.6.RELEASE Maven: org.springframework:spring-tx:4.2.6.RELEASE

转载于:https://my.oschina.net/heiseguoguo/blog/708753

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值