Reputation: 151
I have the following situation :
Project A - Contains a DB-Configurations and Creates Session_Factory at Init.
Project B - Contains entities and using Project A to persist entities.
Project C - Contains entities and using Project A to persist entities.
I am working in OSGi based environment using karaf. I am making small components/Bundles which are using Project A to persist their entities. Project A will be loaded first always as others are dependent on it.
Project A will initiate Session Factory at start but without any packages/classes to scan for entities.
Now any package tries to persist the object using Project A will ended up in exception which is obvious
org.hibernate.MappingException: Unknown entity:
Is there any way i can persist the entities without scanning any packages/classes...?
Upvotes: 1
Views: 960
Reputation: 17874
Hibernate doesn't play well with OSGi. See the caveats at http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch17.html#d5e5021
EclipseLink supports OSGi via the Gemini project, but that has similar limitations: http://wiki.eclipse.org/Gemini/JPA/Documentation/Limitations
Apache Aries JPA allows you to create a PersistenceUnit per Bundle via a Meta-Persistence header in the manifest: http://aries.apache.org/modules/jpaproject.html. This could allow you to share the persistence.xml in project A between bundles B and C, but that still creates two different PersistenceUnits/SessionFactories, I guess.
Upvotes: 1
Reputation: 1922
SessionFactory has to know about an entity before persisting. In your case, if you register some classes from B and C to A, SessionFactory would probably store some references to these classes, thus breaking modularity.
My suggestion for you would be:
Upvotes: 1