OSGi + Hibernate

前端 未结 5 736
终归单人心
终归单人心 2021-02-04 15:59

Instead of having database actions scattered in four (osgi) bundles, all doing there slightly different things. I want to create a (simple) OSGi bundle that is responsible for a

5条回答
  •  青春惊慌失措
    2021-02-04 16:30

    (If you are using Hibernate Annotations)

    Save all the Entities class loaders when the Hibernate bundle is informed about an annotated class.

    Then do something like this before building your SessionFactory.

    ClassLoad cl = Thread.currentThread().getContextClassLoader();
    try {
     Thread.currentThread().setContextClassLoader(yourClassLoader);
     factory = cfg.buildSessionFactory(); 
    }finally {
     Thread.currentThread().setContextClassLoader(cl);  // restore the original class loader
    }
    

提交回复
热议问题