Search code examples
javahibernatejpaosgiapache-servicemix

OSGI is it possible to have 2 persistence units in 1 bundle


As the title states, is it possible to have 2 persistence units in 1 bundle, and therefore two EntiManagers

In OSGI, a persistence bundle has the following in its pom.xml file :

<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>

where persistence.xml defines the persistence unit

So if it is possible:

  • what is the syntax to define 2 instead ?
  • in my case, the persistence provider is hibernate, would that cause a problem ?

thank you


Solution

  • Yes, the OSGi JPA Specification allows for the Meta-Persistence header to be specified as a comma-separated list of resources. You can read full details in section 127.4.2 ("Meta Persistence Header") of the OSGi Compendium Release 6 Specification.

    You also asked if Hibernate presents a problem. It should not, so long as the JPA Provider implementation you are using is compliant with the OSGi JPA Specification.