我试图在独立模式下运行hibernate ogm(而不是jee容器)。 我的persistence.xml文件如下
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="primary" transaction-type="JTA">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="hibernate.ogm.datastore.provider" value="infinispan"/>
<property name="hibernate.ogm.mongodb.database" value="Heroku Read Only"/>
<property name="hibernate.ogm.mongodb.host" value="host"/>
<property name="hibernate.ogm.mongodb.port" value="99999"/>
<property name="hibernate.ogm.mongodb.username" value="user"/>
<property name="hibernate.ogm.mongodb.password" value="pass"/>
</properties>
</persistence-unit>
</persistence>
在我的主要内容中添加了以下代码
private static EntityManagerFactory entityManagerFactory;
public static void main(String[] args){
entityManagerFactory = Persistence.createEntityManagerFactory( "primary" );
EntityManager entityManager = entityManagerFactory.createEntityManager();
}
当我运行main时,我得到以下异常
线程中的异常&#34; main&#34; org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException: 无法获取JBoss Transactions事务管理器实例
此后所有日志
janv. 06, 2017 5:04:13 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [
name: primary
...] janv. 06, 2017 5:04:13 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.0.1.Final} janv. 06, 2017 5:04:13 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found janv. 06, 2017 5:04:13 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist janv. 06, 2017 5:04:13 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} janv. 06, 2017 5:04:15 PM org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator initiateService INFO: OGM000016: NoSQL Datastore provider: org.hibernate.ogm.datastore.infinispan.impl.InfinispanDatastoreProvider janv. 06, 2017 5:04:15 PM org.hibernate.ogm.transaction.impl.OgmJtaPlatformInitiator initiateService INFO: OGM000075: JBoss Transaction Manager (com.arjuna.ats.jta.TransactionManager) detected on classpath. Using JBossStandAloneJtaPlatform as JTAPlatform implementation janv. 06, 2017 5:04:15 PM org.hibernate.ogm.dialect.impl.GridDialectInitiator$GridDialectInstantiator newInstance INFO: OGM000017: Grid Dialect: org.hibernate.ogm.datastore.infinispan.InfinispanDialect janv. 06, 2017 5:04:15 PM org.hibernate.ogm.dialect.impl.GridDialectInitiator$GridDialectInstantiator newInstance INFO: Grid dialect logs are disabled janv. 06, 2017 5:04:15 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.ogm.dialect.impl.OgmDialect janv. 06, 2017 5:04:15 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl makeLobCreatorBuilder INFO: HHH000422: Disabling contextual LOB creation as connection was null janv. 06, 2017 5:04:15 PM org.hibernate.ogm.cfg.impl.Version <clinit> INFO: OGM000001: Hibernate OGM 5.0.0.CR1 Exception in thread "main" org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException: Could not obtain JBoss Transactions transaction manager instance
at org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform.locateTransactionManager(JBossStandAloneJtaPlatform.java:35)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.retrieveTransactionManager(AbstractJtaPlatform.java:87)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.getTransactionManager(AbstractJtaPlatform.java:98)
at org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy.canRegisterSynchronization(TransactionManagerBasedSynchronizationStrategy.java:39)
at org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform.canRegisterSynchronization(AbstractJtaPlatform.java:131)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.pulse(JtaTransactionCoordinatorImpl.java:141)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.<init>(JtaTransactionCoordinatorImpl.java:92)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl.buildTransactionCoordinator(JtaTransactionCoordinatorBuilderImpl.java:28)
at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:273)
at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1322)
at org.hibernate.ogm.hibernatecore.impl.OgmSessionBuilderDelegator.openSession(OgmSessionBuilderDelegator.java:39)
at org.hibernate.ogm.hibernatecore.impl.OgmSessionBuilderDelegator.openSession(OgmSessionBuilderDelegator.java:25)
at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:174)
at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:83)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:319)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:286)
at org.hibernate.ogm.jpa.impl.OgmEntityManagerFactory.createEntityManager(OgmEntityManagerFactory.java:45)
at com.energielibre.middleware.service.mongodatalayergeneric.Tester.main(Tester.java:26) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform.locateTransactionManager(JBossStandAloneJtaPlatform.java:32)
... 18 more Caused by: java.lang.RuntimeException: java.lang.RuntimeException: missing property file arjuna-properties.xml
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getNamedInstance(BeanPopulator.java:81)
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getDefaultInstance(BeanPopulator.java:49)
at com.arjuna.ats.jta.common.jtaPropertyManager.getJTAEnvironmentBean(jtaPropertyManager.java:42)
at com.arjuna.ats.jta.TransactionManager.transactionManager(TransactionManager.java:72)
... 23 more Caused by: java.lang.RuntimeException: missing property file arjuna-properties.xml
at com.arjuna.common.util.propertyservice.PropertiesFactory.getPropertiesFromFile(PropertiesFactory.java:93)
at com.arjuna.common.util.propertyservice.PropertiesFactory.initDefaultProperties(PropertiesFactory.java:236)
at com.arjuna.common.util.propertyservice.PropertiesFactory.getDefaultProperties(PropertiesFactory.java:66)
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getNamedInstance(BeanPopulator.java:77)
... 26 more
我的依赖是
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<!-- JBoss Transactions dependency -->
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.0.0.CR1</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-infinispan</artifactId>
<version>5.0.0.Alpha1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
答案 0 :(得分:0)
配置存在一些问题,我不确定它是否与您的问题有关。
您将hibernate.ogm.datastore.provider
设置为infinispan
,但随后
你设置hibernate.ogm.mongodb.database
。你在努力工作吗?
使用Infinispan或MongoDB?
您正在使用旧的依赖项,您应该尝试使用Hibernate OGM 5.0.4.Final
您使用hibernate.ogm。 mondogb 。*设置的所有属性都是错误的,您应该使用hibernate.ogm。数据存储区。*。 Check the documentation表示您正在使用的数据库的特定属性
您还可以尝试将jbossjta依赖项替换为:
org.jboss.narayana.jta 纳拉亚纳 - JTA 5.4.0.Final
您不需要数据源,因为您没有处理关系数据库。 Hibernate OGM从配置及其自己的方言中获取信息。
如果问题仍然存在,请告诉我。
编辑:添加第4点