Для тестирования проблемы Hibernate / OGM / MongoDB Docker я создал тест JUnit5.
Я добавил файл persistence.xml в проект в папке:
src / test / 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>
Iзашли в настройки проекта и под:
modules |myProject_test |JPA
У меня есть '+' persistence.xml
, который отображается как «дескриптор конфигурации JPA», поэтому теперь он должен находиться в пути к классам?
Однако, когда я запускаю тест, я получаю:
08 апреля 2019 14:36:54 org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve INFO: HHH000318: Не удалось найти никакой META-INF / persistence.xml файл в пути к классам 8 апреля 2019 г. 14:36:54 org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve INFO: HHH000318: Не удалось найти файл META-INF / persistence.xml в файлеclasspath
Тест игнорируется.
javax.persistence.PersistenceException: Нет поставщика постоянства для EntityManager с именем goStopHandleMongoDBPersistenceUnit
в javax.persistence.Persistence.createEntityManagerFavaв javax.persistence.Persistence.createEntityManagerFactory (Persistence.java:54) в com.gostophandle.entity.MotorcycleTest.init (MotorcycleTest.java:25) в sun.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) в sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) в sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java.Java: 498) в org.junit.platform.commons.util.ReflectionUtils.invokeMethod (ReflectionUtils.java:628) в org.junit.jupiter.engine.execution.ExecutableInvoker.invoke (ExecutableInvoker.java:117) в org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda $ invokeBeforeAllMethods $ 9 (ClassTestDescriptor.java:376) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (Throwablegup.it).engine.descriptor.ClassTestDescriptor.invokeBeforeAllMethods (ClassTestDescriptor.java:375) в org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before (ClassTestDescriptor.java:201) в org.junitor.jt.ClassTestDescriptor.java:77) в org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 5 (NodeTestTask.java:132) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector.jlat:73) в org.suort.hunit.NodeTestTask.lambda $ executeRecursively $ 7 (NodeTestTask.java:125) в org.junit.platform.engine.support.hierarchical.Node.around (Node.java:135) в org.junit.platform.engine.support.hierarNodeTestTask.lambda $ executeRecursively $ 8 (NodeTestTask.java:123) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (ThrowableCollector.java:73) в org.junit.ierarch.org..executeRecursively (NodeTestTask.java:122) в org.junit.platform.engine.support.hierarchical.NodeTestTask.execute (NodeTestTask.java:80) в java.util.ArrayList.forEach (ArrayList) .java или java.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll (SameThreadHierarchicalTestExecutorService.java:38) в org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 5 (NodeTestTask.java:139) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute (Throwableavajunit.or)..platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 7 (NodeTestTask.java:125) в org.junit.platform.engine.support.hierarchical.Node.around (Node.java:135) вorg.junit.platform.engine.support.hierarchical.NodeTestTask.lambda $ executeRecursively $ 8 (NodeTestTask.java:123) в org.junit.platform.engine.support.hierarchical.ThrowableCollector.execu73oror или org ().junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively (NodeTestTask.java:122) в org.junit.platform.engine.support.hierarchical.NodeTestTask.execute (NodeTestTuntjatjt.jt).engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit (SameThreadHierarchicalTestExecutorService.java:32) при org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute (HierarchicalTestExecutor.java:57) при org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute (HierarchicalTestEngine.java:51) в org.junit.platform.launcher.core.DefaultLauncher.execute (DefaultLauncher.java:229) в org.junit.platform.launcher.aa $ $$ 6 (DefaultLauncher.java:197) на org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams (DefaultLauncher.java:211) в org.junit.platform.launcher.core.DefaultLauncher.execute (DefaultLauncher.java:191) в org.junit.platform.launcher.teauncDefaultLauncher.java:128) в com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs (JUnit5IdeaTestRunner.java:69) в com.intellij.rt.execution.junit.IestaTestRunner для юниверсов по оружию.rt.execution.junit.JUnitStarter.prepareStreamsAndStart (JUnitStarter.java:242) в com.intellij.rt.execution.junit.JUnitStarter.main (JUnitStarter.java:70)
1031
1031 *файл persistence.xml не найден?TIA.
BTW - файл persistence.xml отлично работает при развертывании в EAR на JBoss WildFly 16.0.0.Final и обращается к моей базе данных MongoDB с помощью JPA: Hibernate / OGM.
У меня возникли некоторые проблемы с доступом к MongoDB в контейнере Docker, и было предложено (Red Hat) протестировать MongoClient, сгенерированный Hibernate OGM.