标签:style http io ar color os sp java on
准备将公司的老应用迁移到OSGI karaf平台上。很吐血的一点就是hibernate。 这玩意,真是超级麻烦的一个工程。除非是改源码。
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(); } } |
标签:style http io ar color os sp java on
原文地址:http://blog.csdn.net/u014311051/article/details/41851803