Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsTransaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1058822/#msg_1058822
After searching this forum and doing some internet research and lots of trial and error, I am still stuck with the question what would be the best option to handle transactions in Virgo. I am using:
Spring 3.1
Hibernate 3.6.0
PostgreSQL 9.2
Virgo 3.6.1
Java 7 on Ubuntu 12.10, 64bit
I currently ended up with this design:
A configuration bundle exports JDBC and hibernate properties as a service.
All (currently three) OSGi bundles that contain Hibernate entities import these properties as a service. Furthermore, each of these bundles sets up an own pooled datasource, session factory and transaction manager (HibernateTransactionManager).
A am not using JTA. If an operation spans multiple transactional service calls, a "best effort" strategy handles potential errors.
I am not happy with this solution, though and wonder what is currently considered "best practice" in my scenario.
I'd prefer a solution like this:
A central registry of persistent entities that all bundles can contribute to.
A single pooled datasource
A single session factory that is consumed by all multiple bundles
A single transaction manager that is consumed by multiple bundles
Is this feasible in an OSGi environment? If so, how??
]]>Lars Behnke2013-05-15T09:17:08-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1058975/#msg_1058975
http://jaxenter.de/Modulare-Enterprise-OSGi-Anwendungen%3A-Let%E2%80%99s-transact%21-5715.html.
It does not cover Virgo but describes how to use Persistence Bundles and transactions in an Enterprise OSGi environment.
You said you want to use a single persistence unit that contains entities from different bundles. This is not possible according to the Enterprise OSGi Spec. A persistence bundle must contain the persistence.xml and all the entity classes. Check out this discussion: http://www.eclipse.org/forums/index.php/t/457852/.
I think this will be the same in Virgo.
If you want to use Hibernate in an OSGi environment you have to use a Hibernate version with OSGi support. Check out the latest 4.3.0 Beta release.
]]>Sebastian Lorenz2013-05-16T06:29:47-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1059129/#msg_1059129
thanks for your reply. The linked posts made some things clearer.
I conclude that these are my options:
(1) Using JDBC transactions that do not cross bundle boundaries. Multiple bundles should not share persistent entities. Error handling in an best effort strategy (actually, thats what I am doing now)
(2) Using a JTA implementation such as Atomikos to enable transactions across multiple bundles.
BTW: Hibernate 3.6 repackaged as OSGi bundle(s) works for me perfectly.]]>Lars Behnke2013-05-16T21:20:07-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1059192/#msg_1059192
In my setup I use Gemini Blueprint for dependency injection and Gemini JPA (hard-wired with Eclipse Link) for the JPA stuff. In this setup you would:
1. create a Persistence Bundle containing your entities and the persistence.xml
2. Gemini JPA together with DB Access (for the DB Driver) will find that bundle and make an EntityManagerFactory available as an OSGi service
3. create a transaction manager for the EntityManagerFactory and and make it available as an OSGi service too.
All bundles that access the PU will get the EntityManagerFactory and the transaction manager from the OSGi context. As described in the forum link above I tried to put entities in different bundles and access them from a single Persistence Bundle. If you do this with Gemini JPA/Eclipse Link then you will lose Eclipse Links weaving capabilities, but it works.
I tried a similar setup with Hibernat OSGi. You can't use Hibernate OSGi together with Gemini JPA so you will have to get the DB driver yourself and register the EntityManagerFactory as a service manually. But then you will be able to use entities from different bundles in a single PU.
]]>Sebastian Lorenz2013-05-17T08:18:34-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1059653/#msg_1059653
Lars Behnke2013-05-21T06:21:26-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1059834/#msg_1059834
I also use xbean-spring (JNDI) to facilitate integration with hibernate.
From that time I helped Atomikos to "OSGify" their TM.
Please have a look of the different bundle and eventually create issue. I'm interested in your feedback. ]]>Pascal Leclercq2013-05-21T19:56:27-00:00Re: Transaction management in Virgo
https://www.eclipse.org/forums/index.php/mv/msg/487562/1062813/#msg_1062813
Another interesting approach to modularize the Hibernate sessionfactory on theserverside.com:
www.theserverside.com/news/thread.tss?thread_id=63223
@pascal: Thanks for the links. I'll investgate the projects.
Sorry for not posting a valid URL. The forum policy prevents this.]]>Lars Behnke2013-06-10T20:27:18-00:00