hibernate4与hibernate5的一些区别

1: 获取sessionFactory
  hibernate4:

private static Configuration configuration = null;
private static SessionFactory sessionFactory = null;
private static ServiceRegistry serviceRegistry = null;
public static void main(String[] args) {
    try {
        configuration = new Configuration().configure();
        serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
       sessionFactory = configuration.buildSessionFactory(serviceRegistry);
         } catch (HibernateException e) {
             e.printStackTrace();
         }
     }

  hibernate5:

StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder().configure("hibernate_cfg.xml").build();
        try {
            sessionFactory = new MetadataSources(standardServiceRegistry).buildMetadata().buildSessionFactory();
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            System.out.println("echo all error");
        }

你可能感兴趣的:(hibernate,java随笔)