为了测试Hibernate / OGM / MongoDB Docker问题,我创建了一个JUnit5测试。
我已将persistence.xml添加到文件夹中的项目中:
的src /测试/ META-INF
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="goStopHandleMongoDBPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.3"/>
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.10"/>
<!-- <property name="hibernate.transaction.jta.platform" value="JBossTS"/> -->
<!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAS"/> -->
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
<property name="hibernate.ogm.datastore.provider"
value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.datastore.grid_dialect"
value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
<property name="hibernate.ogm.datastore.database" value="goStopHandleDB"/>
<property name="hibernate.ogm.datastore.host" value="172.17.0.2:32844"/>
</properties>
</persistence-unit>
</persistence>
我已进入项目设置并且在:
模块| myProject_test | JPA
我'''是persistence.xml
它看起来像'JPA配置描述符',所以它现在应该在类路径中?
但是,当我运行测试时,我得到:
org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve INFO:HHH000318:在类路径中找不到任何META-INF / persistence.xml文件4月08日,2019 2:36:54 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve INFO:HHH000318:在类路径中找不到任何META-INF / persistence.xml文件
测试被忽略了
javax.persistence.PersistenceException:没有名为goStopHandleMongoDBPersistenceUnit的EntityManager的持久性提供程序
在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)的javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)at com.gostophandle.entity.MotorcycleTest.init(MotorcycleTest.java:25)at sun。在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)的java.lang.reflect.Method.invoke上的reflect.NativeMethodAccessorImpl.invoke0(Native Method)方法.java:498)org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:628)org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:117)at org orjun.junit上的org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)中的.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda $ invokeBeforeAllMethods $ 9(ClassTestDescriptor.java:376)。 jupiter.engine.descriptor.ClassTestDescriptor.invokeBeforeAllM方法(ClassTestDescriptor.java:375)org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:201)org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:77) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 5(NodeTestTask.java:132)org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 7(NodeTestTask.java:125)org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)at org .unit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 8(NodeTestTask.java:123)org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org。在org.junit.platform.engine.support.h上的junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)位于org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll的java.util.ArrayList.forEach(ArrayList.java:1257)中的ierarchical.NodeTestTask.execute(NodeTestTask.java:80)(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 5(NodeTestTask.java:139)org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 7(NodeTestTask.java:125)org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)at org .unit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 8(NodeTestTask.java:123)org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)at org。 org中的junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) org.junit.platform上的org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)中的.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) org.junit.platform.launcher.core上的org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)中的.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) org.junit.platform.launcher.core.DefaultLauncher.lambda上的.DefaultLauncher.execute(DefaultLauncher.java:229)$ org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams执行$ 6(DefaultLauncher.java:197) DefaultLauncher.java:211)org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)at com.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)at com .intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestR unner.java:69)at com.intellij.rt.exe.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
有没有找到persistence.xml的想法? TIA。
BTW - 当在JBoss WildFly 16.0.0.Final上的EAR中部署时,persistence.xml一切正常,它使用JPA:Hibernate / OGM访问我的MongoDB数据库。
我在Docker容器中访问MongoDB时遇到了一些问题,并且已经建议(由Red Hat提供)我测试Hibernate OGM生成的MongoClient。
使用标准的src/test/resources
资源根目录,尤其是在使用像Maven这样的构建系统时。
如果persistence.xml
放在src/test/resources/META-INF/persistence.xml
,它应该工作。