hibernate5创建SessionFactory不同于hibernate4和hibernate3,下面是代码示例、
package top.scorpion.util; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; public class HibernateUtil { public static SessionFactory getSessionFactory() { SessionFactory sessionFactory = null; final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure().build(); try { sessionFactory = new MetadataSources(registry).buildMetadata() .buildSessionFactory(); } catch (Exception e) { StandardServiceRegistryBuilder.destroy(registry); } return sessionFactory; } }