I have code using JPA and everything works fine in my development environment and in unit tests. But deploying my modules into the OSGi target environment, I regularly run into the weirdest class loading issues. I really like OSGi, but if I can't fix this once and for all, I'm going to get stark raving mad. And as long as I don't understand what classes need to be seen by which other classes, I'm never going to get the OSGi stuff set up properly.
So, as far as I can see, I have the following items that may or may not be visible from some piece of running code, let's call them "subjects":
persistence.xml
javax.persistence
And I have the following situations in my code:
EntityManagerFactory
and an EntityManager
EntityManager
to put them into its persistence contextSo, in which of the above situations do I need which subjects to be visible?
I guess it's probably obvious that
Create these bundles:
Visibility:
[EDIT] What you must understand is how OSGi classloading works: If you have two bundles A and B and you import both are used in C, then A can't see B and B can't see anything from A. C can see both.
Now A and B use a library bundle X. If A creates some instance from X and passes that to C who in turn passes it to B, you'll get errors since the X from A is not the same X as from B. Each X is completely encapsulated from the outside world.
In Java lingo: The classes from X are created using different classloaders and even if the name is the same, classes from different classloaders are never the same.
This is why you must avoid to import X from two different paths.