Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Transaction management in Virgo( Which design is considered "best practice"?)
Transaction management in Virgo [message #1058822] Wed, 15 May 2013 09:17 Go to next message
Lars Behnke is currently offline Lars Behnke
Messages: 4
Registered: May 2013
Junior Member
Hello,

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??

[Updated on: Tue, 21 May 2013 06:36]

Report message to a moderator

Re: Transaction management in Virgo [message #1058975 is a reply to message #1058822] Thu, 16 May 2013 06:29 Go to previous messageGo to next message
Sebastian Lorenz is currently offline Sebastian Lorenz
Messages: 38
Registered: November 2010
Member
There has been a nice article series in Eclipse Magazin (german) about modular OSGi applications:
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.
Re: Transaction management in Virgo [message #1059129 is a reply to message #1058975] Thu, 16 May 2013 21:20 Go to previous messageGo to next message
Lars Behnke is currently offline Lars Behnke
Messages: 4
Registered: May 2013
Junior Member
Sebastian,
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.

[Updated on: Thu, 16 May 2013 21:27]

Report message to a moderator

Re: Transaction management in Virgo [message #1059192 is a reply to message #1059129] Fri, 17 May 2013 08:18 Go to previous messageGo to next message
Sebastian Lorenz is currently offline Sebastian Lorenz
Messages: 38
Registered: November 2010
Member
I would recommend using Hibernate OSGi or some other OSGi Enterprise JPA Spec compliant way to work with JPA in an OSGi environment.
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.
Re: Transaction management in Virgo [message #1059653 is a reply to message #1059192] Tue, 21 May 2013 06:21 Go to previous messageGo to next message
Lars Behnke is currently offline Lars Behnke
Messages: 4
Registered: May 2013
Junior Member
Hi Sebastian, thanks for sharing your setup. Seems to be the perfect solution for my transaction problem. Unfortunately, I am currently bound to some legacy libraries (Hibernate 3.6.x) and must postpone the spec compliant design until the next major release. Anyway, thanks again for your help!
Re: Transaction management in Virgo [message #1059834 is a reply to message #1059653] Tue, 21 May 2013 19:56 Go to previous messageGo to next message
Pascal Leclercq is currently offline Pascal Leclercq
Messages: 7
Registered: July 2009
Junior Member
Few years ago I create a POC to evaluation JPA/JTA over OSGI.


You can find source here : https://code.google.com/p/dynaresume/source/browse/#svn%2Fbranches%2FspringDMserver2.0


The idea is to configure Atomikos TM and publish It as a OSGi service see :

https://code.google.com/p/dynaresume/source/browse/branches/springDMserver2.0/infrastructure/org.dynaresume.infrastructure.jtatransaction/META-INF/spring/module-context.xml

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.
Re: Transaction management in Virgo [message #1062813 is a reply to message #1059834] Mon, 10 June 2013 20:27 Go to previous message
Lars Behnke is currently offline Lars Behnke
Messages: 4
Registered: May 2013
Junior Member
For the sake of completeness:
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.

[Updated on: Mon, 10 June 2013 20:30]

Report message to a moderator

Previous Topic:Spring annotation config
Next Topic:Locked bundle on Windows prevents from Virgo IDE to resolve artefact
Goto Forum:
  


Current Time: Sat Sep 20 14:09:07 GMT 2014

Powered by FUDForum. Page generated in 0.03077 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software