Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] EJB 3.0 usage

We are developing a client (RCP) / server (OSGi) application that uses EJB 3.0 for a portion of its persistence model. We are using Hibernate with a layer of custom code that allows Hibernate to work in the OSGi plug-in architecture. I originally designed the application to make use of EJB 3.0 in both the client and the server; however, Hibernate takes too long to startup so all use of the EJB 3.0 EntityManager was pushed to the server.

The biggest issue with getting Hibernate to work with the OSGi plug-in architecture is, of course, the plug-in classloader. Hibernate can't find your Entities defined in plug-ins without some help. The problem was solved by a combination of the Eclipse buddy policy, and playing games with the context classloader and persistence.xml.

Another problem we had was with the persistence.xml file. Part of our application is designed as a set of frameworks that are designed to be extensible, and some of these frameworks use the EntityManager. We needed a way to make the persistence.xml file extensible. The solution was to create the persistence.xml file on-the-fly at runtime when we initialize the EntityManagerFactory. A side benefit of creating the persistence.xml at runtime is the ability to easily switch between different database vendors. We typically use MySQL for debug / test and DB2 for production. Switching databases is a simple matter of specifying which database plug-in to load in the launch configuration.

Our solution ties everything together through a persistence plugin that defines an extension point allowing other plug-ins to declare entities as an extension. This allows multiple plug-ins to contribute entities (as extensions) to the same persistence context. The plug-in also defines an OSGi service for obtaining an EntityManager. It also gives us the ability to manage the same Entity in multiple persistence contexts. We are not currently using this ability, but I can see a way we may use it in the future.

Since EclipseLink is developing a competing solution to Hibernate, I'm very interested in the work. I'd really like to see an OSGi friendly EJB 3.0 solution. I'll try to have a deeper look into EclipseLink in the next few weeks.


Back to the top