I'm using Apache karaf 4.2.6 .I have the following config:
<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>
I made a simple method to make a transaction like this:
@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);
}
}
}
the apache aries config (org.apache.aries.transaction.cfg) under /etc is this:
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
The problem is that it does not commit into the txlogTest log files .I'm wondering if Apache aries support recover failed transaction or not . Actually i remember when i have used websphere when it starts it recover all the failed transaction from tranlog folder. Can i make something like that with karaf/Apache Aries?
Thanks
You may check out a great jump start Karaf JPA example here
You can use @Transactional annotation simply as follow:
According to this documentation transaction recovery depends on your resource which is recoverable or not: