码迷,mamicode.com
首页 > Web开发 > 详细

osgi 环境下 hibernate 4 配置

时间:2014-12-10 21:16:48      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   sp   java   on   

准备将公司的老应用迁移到OSGI karaf平台上。很吐血的一点就是hibernate。 这玩意,真是超级麻烦的一个工程。
classload是最头痛的一个问题。在Hibernate4上利用注册服务的方式 实现了 classloader的代理。
顺便提一句想用Hibernate3做reloadclass的同学们别妄想了。

除非是改源码。

标签: Hibernate Karaf

[1].[代码] 核心代码创建 SessionFactory 跳至 [1]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
     * Rebuild hibernate session factory
     *
     */
    public static void rebuildSessionFactory() {
        try {
            // create a BootstarpRegistry
            BootstrapServiceRegistry bootstrapServiceRegistry = new BootstrapServiceRegistryBuilder()
            // pass in a class-loader Hibernate should use to load application
            // classes
                    .withApplicationClassLoader(org.postgresql.Driver.class.getClassLoader())
                    // pass in a class-loader Hibernate should use to load
                    // resources
                    .withResourceClassLoader(HibernateSessionFactory.class.getClassLoader()).build();
 
            // create a ServiceRegistry
            ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder(bootstrapServiceRegistry);
 
            // clear
            configuration = new Configuration();
            // read config
            URL u = HibernateSessionFactory.class.getClassLoader().getResource(configFile);
            configuration.configure(u);
            registryBuilder.applySettings(configuration.getProperties());
            // build ServiceRegistry
            ServiceRegistry serviceRegistry = registryBuilder.buildServiceRegistry();
 
            // create SessionFactory
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        } catch (Exception e) {
            System.err.println("%%%% Error Creating SessionFactory %%%%");
            e.printStackTrace();
        }
    }

osgi 环境下 hibernate 4 配置

标签:style   http   io   ar   color   os   sp   java   on   

原文地址:http://blog.csdn.net/u014311051/article/details/41851803

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!