2012-06-20 83 views
0

我試圖做一個簡單的吉斯持久性測試,不幸的是我得到了這一點:的Maven無法找到的persistence.xml

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

有人可以幫忙嗎?

+1

post persistence.xml – Ilya

回答

0

Fix'd我不知道爲什麼,但我修改我的pom.xml改變所有吉斯版本的方式:

<version>${guice.version}</version> 

還屬性

<properties> 
    <guice.version>3.0</guice.version> 
</properties> 

,它無論如何努力的,謝謝。

1

你的persistence.xml應該發現,在運行期間,在

WEB-INF/classes/META-INF/ . 

然而,投入開發資源文件夾/ META-INF /是做正確的事,但還不夠。你必須確保在eclipse中資源文件夾被用作「源文件夾」。

要使用文件夾作爲源,右鍵單擊包瀏覽器面板中的文件夾,然後右鍵單擊上下文菜單 - >構建路徑 - >用作源文件夾。

然後在Eclipse的WTP構建過程中,Java源文件將被編譯,並將它們的字節碼類文件放置到WEB-INF/classes文件夾中。

同時,在源代碼構建路徑中找到的非Java資源將被批量複製到WEB-INF/classes文件夾中 - 這就是您的JPA驅動程序應該找到持久性defn文件的位置。