/**
*
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();
}
}
|