0
votes

I am using karaf 3.0.3 and the following Hibernate bundles:

161 | Active | 80 | 4.2.12.Final | hibernate-core
162 | Active | 80 | 4.2.12.Final | hibernate-entitymanager
172 | Active | 80 | 4.2.12.Final | hibernate-osgi

With this set-up I cannot get a transaction roll-back to work, although I can deploy the exact same components (JPA DAOs, service layer etc) as a standalone Spring application, and I see roll-backs performed correctly.

What are the gotchas when trying to get transactions to work successfully with OSGI/hibernate?

  • is it something to do with cross-bundle transactions? (My DAOs and service layer are in separate bundles)

If I get not replies here, I will update with more specific information, but first I want to see if this is a common problem with OSGi/hibernate/jpa.

edit after user2007829's comment: The DAOs extend Spring's JpaRepository, and the service layer method is annotated with Spring's @Transactional. I believe in this setup, auto commit should be implicitly off, and the standalone spring app set-up is working as expected. Is that wrong?

How should the persistence unit XML file differ in the OSGI case? Right now the only difference is that the transaction-type is JTA in the karaf case, and I have a declaration like this:

<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/‌​my-datasource)</jta-data-source>
2

2 Answers

1
votes

There are many possible reasons why this could occur. For example your data source might not wrap an XADataSource correctly. In this case it can occur that the EntityManager did not join the transaction or is not enlisted as XA ressource.

Have a look at these tutorials. It is easier to start from a working basis: http://www.liquid-reality.de/x/LYBk http://www.liquid-reality.de/x/C4DK

Unfortunately the tutorials are based on blueprint and aries jpa so it is not exactly spring. You still should be able to use some of the informations. Additionally I can only recommend to switch from spring to blueprint as spring does not support OSGi anymore.

For blueprint there are apache aries which the tutorials are based on or eclipse gemini.

0
votes

And how do you use the hibernate? Do you create a transaction and work within it or are your queries session related? Also, did you set autocommit to false?