I have used Hibernate successfully (including Hibernate Search) in an OSGI / Karaf environment.
If you have some specific questions, i’d be more than happy to help. I have found that Hibernate has some examples of OSGI implementation using Karaf. Karaf has the “features” ability to add all the dependencies, in the right order, for the file you are using. In fact, i think Karaf now has a built in “hibernate” feature, although i built my own features to fine tweak the dependencies and usage. Once Hibernate is available as a service (and the configuration depends on either you are using native hibernate session factory or JPA entity manger), you can have your annotated entities classes in a different OSGI bundle and use them as any other bundle as you describe. The down side of the current OSGI hibernate setup (which is really just a “make it work” set up, and newer versions of Hibernate are promised to make it more OSGI like), is that you need to use the Hibernate.cfg or .xml file to configure that data source and register the entity classes. The examples described in http://docs.jboss.org/hibernate/orm/5.0/devguide/en-US/html/ch17.html <http://docs.jboss.org/hibernate/orm/5.0/devguide/en-US/html/ch17.html> do a good job getting you started. You can have your entities in a separate bundle if you wish or in the same bundle with your session factory singleton. > On May 5, 2015, at 10:43 PM, Jens J Parappallil <jens.parappal...@ibsplc.com> > wrote: > > Hi, > > I am planning to integrate hibernate in my project, I have many bundles which > has entity classes present ( and exported ) . I am planning to have a core > bundle which holds the hibernate session factory etc and manages the > persistence stuff. > > I am thinking how this works out in an OSGi environment where the bundles ( > having entity classes ) can come and go. The hibernate session factory is a > singleton , to be created ones and used. Can it wok with annotated entities > coming and going ? > > This is more of a hibernate question , but any of you guys have envisioned > such a usage pattern and made it work ? > > Thanks > Jens > > > DISCLAIMER: "The information in this e-mail and any attachment is intended > only for the person to whom it is addressed and may contain confidential > and/or privileged material. If you have received this e-mail in error, kindly > contact the sender and destroy all copies of the original communication. IBS > makes no warranty, express or implied, nor guarantees the accuracy, adequacy > or completeness of the information contained in this email or any attachment > and is not liable for any errors, defects, omissions, viruses or for > resultant loss or damage, if any, direct or indirect."