Monday, January 18, 2010

Spring DM & Hibernate on RAP: The classloading hell

In the meantime I set up a RAP application with a hibernate backend that will be integrated through spring DM. Since the hibernate libraries are not bundle-ified I went throught the overall known classloading hell. I had trouble with the Spring LocalContainerEntityManagerFactoryBean, that did not find my persistence unit, although I found some different posts suggesting that it should work. I changed



persistenceXmlLocation to classpath:META-INF/persistence.xml



so it looks in my bundle and there it is. With the default setting "classpath*:META-INF..." it simply seemed to find the file, but couldn't find my persistence units. 


Has anyone made the same experiences ?


I'm looking forward to work with the osgi-ified spring services in the app now.

8 comments:

Frederic Conrotte said...

Do you expect the persistence unit to be exposed to the external world?

Thomas Kratz said...

I wanted the persistence unit to live in a different bundle than the spring context.

Frederic Conrotte said...

What I would do is keep the DAO interface and persistence unit within one bundle and expose the DAO service if needed.

Otherwise, you can also create a service that expose the persistence unit xml files as a byte[]

Thomas Kratz said...

Thats exactly what I did now. Now I'm fighting with activeMQ for tonight.

Frederic Conrotte said...

For ActiveMQ I spent sometimes making it work, but it's not that hard.

you can have a look at bundles here:
http://code.google.com/p/ofmp/

Herman Lintvelt said...

Thomas, how have you progressed? I'm busy with a RAP project, and need to decide on the persistence/services layer and how to integrate. I'm also considering either Hibernate and Spring-DM, as you are doing, or else just using EclipseLink directly from the RAP side.

Thomas Kratz said...

Hi herman, it works fine now. I have spring transactions and dependency injection of entitiymanagers. Really fine.

Herman Lintvelt said...

That is good to hear. If I run into problems I'll beg for your expert advise :-).

Using Mapstruct with Protobuf3