0 Replies Latest reply on Apr 9, 2014 5:23 AM by jaakkorautiainen

    JBoss 7.2.0.Final + OSGi: Spring 3.x Hibernate 3.x JPA migration

    jaakkorautiainen

      Hello there!

       

      I have an application based on Spring Framework. Due to modularity and system management concerns, I am now migrating this application to JBoss OSGi.

       

      The version of Spring I use is 3.2.3.Final and the version of Hibernate is 3.6.1.Final. My application uses JPA annotations (@Transactional, @PersistenceContext) and lets Spring handle the implementation and wiring. The entity managers are injected by the org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean, which gets the data source through JNDI. The persistence unit is described in the META-INF/persistence.xml file.

       

      Hibernate 3 libraries are not OSGi-compatible from what I have heard, so for that reason I first tried to update the Hibernate version to 4.2.0.Final. The later versions appear to require a newer version of OSGi Framework. With that version, the problem was Spring not injecting the entity managers. It just silently failed and then my application crashed on a null pointer exception from an entity manager reference.

       

      It would make sense to use the JPA provider JBoss comes with, aka the Hibernate 4 system module. It appears that the Spring 3.x framework is not compatible with Hibernate 4.x, so I decided the next course of action is to build a Hibernate 3 JBoss module. I am not sure building the Hibernate 3 module is the right choice of action, though. Even if I build it, I don't appear to get rid of the Hibernate 3 problems on OSGi. It also appears to be tricky to make sure that the Hibernate 3 module is correctly added as a dependence and as a JPA provider for the OSGi bundles. It becomes even more awkward when you need to provide the module for 3rd party bundles also, such as Spring.

       

      The most beautiful solution on JBoss-OSGi, I guess, would be based on Blueprint. Especially the solutions posted online on various forums based on Aries JPA + Aries Blueprint look very suitable for my needs. I use the Eclipse Gemini Blueprint since it's based on Spring DM and the application is Spring-based. I also need to support both Spring and Blueprint configurations side-by-side due to migration. However, the Gemini JPA provider appears to require an OSGi Core 4.3 compliant environment. Is there a chance to make it work in JBoss 7.2.0.Final? As far as I know, the OSGi subsystem included in JBoss AS 7.2.0.Final is only OSGi Core 4.2  -compliant.

       

      My data objects are POJO's and located in another OSGi bundle. I would like to keep it that way and have tried to manage the concern by listing the persistent object classes in the persistence.xml and then adding an OSGi import-package from the DAO bundle to the POJO bundle. Does this arrangement cause a problem?

       

      Which JPA provider should I use on JBoss AS 7.2.0.Final OSGi environment, when my application is coming from Spring3+Hibernate3 background?

       

      Has anyone migrated a similar JPA setup successfully on JBoss AS 7 and if so, how?

       

      I will deeply appreciate any comments, help and ideas about the subject.

       

      Best regards,

      Jaakko Rautiainen