当前位置: 动力学知识库 > 问答 > 编程问答 >

java - StandAlone CDI + JTA Without JNDI

问题描述:

I am using CDI + DeltaSpike + Camel in a standalone app.

Here is my current setup :

persistence.xml

<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="RESOURCE_LOCAL">

<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>

</persistence-unit>

Custom properties on EntityManagerFactoryProducer:

properties.put("hibernate.connection.provider_class", "org.example.HikariConnectionProvider");

I'm using DeltaSpike JPA Transaction with (https://deltaspike.apache.org/documentation/jpa.html):

  • org.apache.deltaspike.jpa.api.transaction.TransactionScoped;
  • org.apache.deltaspike.jpa.api.transaction.Transactional;


I would like to use Infinispan to sync my app caches.

According to Infinispan doc:

"It is highly recommended that Hibernate is configured with JTA transactions"

How can I use JTA transactions ?

I tried to change "RESOURCE_LOCAL" to "JTA" but I don't understand what am I supposed to configure for :

  • hibernate.transaction.factory_class
  • hibernate.transaction.jta.platform

I am not using JNDI, and I am not in an application server.

Also, I would like to use @javax.transaction.Transactional instead of DeltaSpike.

网友答案:

Essentially, you are asking how to use most Java EE features without using a Java EE container.

Of course, there are JTA implementations like Atomikos you can embed in a "standalone" application.

On the other hand, it might be a lot easier to start with a full-blown Java EE environment and then ignore or exclude anything you don't need.

App servers are rather lightweight these days, and if a self-contained executable is a must-have for you, then have a look at WildFly Swarm or Payara Micro.

分享给朋友:
您可能感兴趣的文章:
随机阅读: