我试图做一个简单的guice持久性测试,不幸的是我得到了这个:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named test
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)
at utfpr.edu.br.client.PersistenceTestModule.getInjector(PersistenceTestModule.java:22)
at utfpr.edu.br.client.PessoaDaoTeste.<init>(PessoaDaoTeste.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
首先:我的persistence.xml位于资源/ META-INF的正确位置 第二:是的,我把正确的提供者:org.hibernate.ejb.HibernatePersistence
有人可以帮忙吗?
答案 0 :(得分:1)
您应该在运行时
找到您的persistence.xmlWEB-INF/classes/META-INF/ .
但是,放入开发文件夹资源/ META-INF /是正确的做法,但还不够。您必须确保资源文件夹在eclipse中用作“源文件夹”。
要将文件夹用作源,请右键单击package explorer面板上的文件夹,然后右键单击context-menu - &gt;构建路径 - &gt;用作源文件夹。
然后在eclipse WTP构建期间,将编译Java源文件,并将其字节码类文件放入WEB-INF / classes文件夹中。
同时,在源构建路径中找到的非Java资源将被批量复制到WEB-INF / classes文件夹中 - 这就是您的JPA驱动程序应该找到持久性定义文件的地方。
答案 1 :(得分:0)
修复我不知道为什么,但我修改了我的pom.xml,改变了所有guice版本:
<version>${guice.version}</version>
也是属性
<properties>
<guice.version>3.0</guice.version>
</properties>
无论如何,这都很有效。