1.
//创建服务注册对象
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();//创建会话工厂对象
SessionFactory sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
2.
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
3.
hibernate创建表时,会在create后面跟上type=MyISAM,此时用的数据库方言是org.hibernate.dialect.MySQLDialect,这样建表会出错,javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement;把方言改成org.hibernate.dialect.MySQL5InnoDBDialect,create后面会跟上engine=InnoDB。
之前:
之后: