Hibernate5的Configuration:
Hibernate5的Configuration.jpg
StandardServiceRegistry
public class HibernateUtil {
private final static SessionFactory FACTORY = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
StandardServiceRegistry standardRegistry = null;
Metadata metadata = null;
SessionFactory factory = null;
try {
standardRegistry = new StandardServiceRegistryBuilder().configure().build();
metadata = new MetadataSources(standardRegistry)
.getMetadataBuilder()
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.build();
factory = metadata.getSessionFactoryBuilder().build();
// configiguration = new Configuration().configure();
// builder = new ServiceRegistryBuilder()
// .applySettings(configiguration.getProperties());
// registry = builder.buildServiceRegistry();
// factory = configiguration.buildSessionFactory(registry);
System.out.println(factory);
} catch (Exception e) {
e.printStackTrace();
}
return factory;
}
Hibernate4的Configuration:
Hibernate4的Configuration.jpg
ServiceRegistry
private static SessionFactory buildSessionFactory() {
Configuration configuration=null;
ServiceRegistry serviceRegistry=null;
ServiceRegistryBuilder builder=null;
SessionFactory factory=null;
try {
// Create the SessionFactory from hibernate.cfg.xml
configuration = new Configuration().configure();
builder=new ServiceRegistryBuilder()
.applySettings(configuration.getProperties());
serviceRegistry = builder.buildServiceRegistry();
factory=configuration.buildSessionFactory(serviceRegistry);
} catch (Exception e) {
e.printStackTrace();
}
return factory;
}
Hibernate3的Configuration:
Hibernate3的Configuration.jpg