No, they do not.
I removed all other annotations and reduced inheritance and turned out to be a very simple class. Problem still exists.
What was not mentioned in my post (because I thought it didn't matter) was that I run it inside the OSGi container (if that matters, Felix). Now such a container protects different "bundles" from each other, so they cannot see each other's classes until you specifically "export" packages.
The annotated classes were in a different package than my persistence.xml, and I suggested that I could just import the annotated classes from another package and execute persistence initialization material elsewhere. It turns out I canβt, although I donβt understand why.
So, if you use JPA along with OSGi packages, you must make sure that:
- Annotated classes and persistence.xml are together in one set
- this package exports a package containing annotated classes
- stability units are specified in the package manifest file
Then you can perform the actual persistence actions (for example, calling EntityManager.persist) in different packages.
As a side note, I got similar weird errors when trying to use JAXB annotations for different packages. It seems that JAXBContext and / or ObjectFactory should be created in the same package that contains the annotated classes. I could not do this, but investing in the same bunch helped.
It would be great if someone with a deeper understanding of OSGi, class loading and annotations could comment on what could happen here.
Update : exporting / importing appropriate annotation packages may allow you to have persistence.xml and annotated classes in different packages, see. However, not tested.
Hanno Fietz Jun 23 '09 at 18:12 2009-06-23 18:12
source share