2
1
0

在 Hibernate 4 升级到 5 的时候老的 sessionFactory 出现错误。

	public static SessionFactory initSession() {
		Configuration configuration = new Configuration();
		configuration.configure();
		serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		return sessionFactory;
	}
    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      你可以使用下面的代码来在 Hibernate 5 中初始化:


          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;
          }
      
      


        CommentAdd your comment...