框架之Hibernate Configuration

Hibernate5的Configuration:

框架之Hibernate Configuration_第1张图片
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:

框架之Hibernate Configuration_第2张图片
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:

框架之Hibernate Configuration_第3张图片
Hibernate3的Configuration.jpg

你可能感兴趣的:(框架之Hibernate Configuration)