We migrated a Hibernate layer of a Java-Desktop-application from 4 (4.1.19) to Hibernate 5 (5.2.17).
We still use legacy HBM mapping-files. The initialization of the Session factory instance takes now more time (double).
// Initialization-Method - Hibernate 4.1.19 - ~ 5 seconds
public synchronized SessionFactory getSessionFactory() {
private SessionFactory sessionFactory = null;
try {
Configuration configuration = new Configuration();
configuration.configure();
// add custom-Hibernate-Interceptor
configuration.setInterceptor(new myInterceptor());
// Build a Service-Registry
ServiceRegistry aRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
// Build the SessionFactory
sessionFactory = (SessionFactoryImpl) configuration.buildSessionFactory(aRegistry);
}
catch (Throwable ex) {
....
}
return sessionFactory;
}
// Initialization-Method - Hibernate 5.2.17 ~10 seconds
private synchronized SessionFactory getSessionFactory() {
private SessionFactory sessionFactory = null;
try {
// create configuration
Configuration configuration = new Configuration();
// add custom-Hibernate-Interceptor
configuration.setInterceptor(new myInterceptor());
// Build a Service-Registry
aServiceRegistry = new StandardServiceRegistryBuilder(bootstrapRegistry)
.applySettings(configuration.getProperties())
.configure()
.build();
// Build the MetadataSources
MetadataSources aSources = new MetadataSources(aServiceRegistry);
// Build the Metadata
Metadata metadata = aSources.getMetadataBuilder().build();
// Build the SessionFactory
sessionFactory = metadata.getSessionFactoryBuilder().build();
}
catch (Throwable ex) {
....
}
return sessionFactory;
}