我使用的是Apache karaf 4.2.6 .I,配置如下:
<repository>mvn:org.ops4j.pax.jdbc/pax-jdbc-features/1.3.5/xml/features</repository>
<feature name="karaf-jpa-example-datasource" version="${project.version}">
<config name="org.ops4j.datasource-demo">
osgi.jdbc.driver.class=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/demo
xa=true
pool=aries
user=postgres
password=postgres
databaseName=demo
dataSourceName=demo
</config>
<capability>
osgi.service;objectClass=javax.sql.DataSource;effective:=active;osgi.jndi.service.name=demo
</capability>
</feature>
<feature name="karaf-jpa-example-common" version="${project.version}">
<feature>transaction</feature>
<feature>jndi</feature>
<feature>pax-jdbc-config</feature>
<feature>pax-jdbc-postgresql</feature>
<feature>pax-jdbc-pool-aries</feature>
<feature>jdbc</feature>
<feature dependency="true">aries-blueprint</feature>
<feature version="[2,3)">jpa</feature>
<feature version="[5,6)">hibernate</feature>
<!--<feature version="[3,4)">openjpa3</feature>-->
<bundle>mvn:org.apache.karaf.examples/karaf-jpa-example-provider-api/${project.version}</bundle>
</feature>我创建了一个简单的方法来进行这样的事务:
@Transactional(Transactional.TxType.REQUIRES_NEW)
@Override
public void add(String flight, String customer) {
int t = 0;
for (;;) {
System.out.println("adding new booking " + t);
Booking booking = new Booking();
booking.setCustomer(customer);
booking.setFlight(flight);
entityManager.persist(booking);
t++;
if (t > 10) {
System.out.println("good bye ");
Runtime.getRuntime().halt(-1);
}
}
}/etc下的apache aries配置(org.apache.aries.transaction.cfg)如下:
aries.transaction.recoverable=true
aries.transaction.timeout=10800
aries.transaction.howl.logFileDir=${karaf.data}/txlogTest
aries.transaction.howl.maxLogFiles=2
aries.transaction.howl.maxBlocksPerFile=512
org.apache.karaf.features.configKey = org.apache.aries.transaction问题是它没有提交到txlogTest日志文件中。我想知道Apache aries是否支持恢复失败的事务。实际上,我记得当我使用websphere时,当它启动时,从tranlog文件夹中恢复所有失败的事务。我能用karaf/Apache Aries做这样的事情吗?
谢谢
发布于 2019-09-23 16:39:42
您可以查看一个很好的快速入门Karaf JPA example here
您可以简单地使用@Transactional注解,如下所示:
@Transactional
public class BookingServiceImpl implements BookingService {
@PersistenceContext(unitName = "booking-hibernate")
private EntityManager entityManager;
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
@Override
public void add(String flight, String customer) {
Booking booking = new Booking();
booking.setCustomer(customer);
booking.setFlight(flight);
entityManager.persist(booking);
}
}根据this documentation的说法,事务恢复取决于可恢复或不可恢复的资源:
aries.transaction.recoverable属性
是启用对可恢复资源的支持与否的标志。可恢复资源是一个事务性对象,如果提交了事务,则将其状态保存到稳定存储中;如果回滚了事务,则可以将其状态重置为事务开始时的状态。在提交时,事务管理器在与可恢复资源通信时使用两阶段XA协议,以确保在所提交的事务中涉及多于一个可恢复资源时的事务完整性。事务性数据库和Apache ActiveMQ等消息代理就是可恢复资源的示例。可恢复的资源使用JTA中的javax.transaction.xa.XAResource接口表示。默认值为true
https://stackoverflow.com/questions/57994628
复制相似问题