在 Hibernate 4 升級到 5 的時候老的 sessionFactory 出現錯誤。api
public static SessionFactory initSession() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; }
你可使用下面的代碼來在 Hibernate 5 中初始化:session
public static SessionFactory initSession() { Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new StandardServiceRegistryBuilder().configure().build(); Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build(); sessionFactory = metadata.getSessionFactoryBuilder().build(); return sessionFactory; }
app