当前位置: 代码迷 >> 综合 >> 3.session flush 隔离级别:工具类
  详细解决方案

3.session flush 隔离级别:工具类

热度:13   发布时间:2024-01-17 02:39:20.0
package com.bjpowernode.hibernate;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;public class HibernateUtils {private static SessionFactory factory;static {try {//读取hibernate.cfg.xml文件Configuration cfg = new Configuration().configure();//建立SessionFactoryfactory = cfg.buildSessionFactory();}catch(Exception e) {e.printStackTrace();}}public static Session getSession() {return factory.openSession();} public static void closeSession(Session session) {if (session != null) {if (session.isOpen()) {session.close();}}}public static SessionFactory getSessionFactory() {return factory;}
}

package com.bjpowernode.hibernate;import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;/*** 将hbm生成ddl* @author Administrator**/
public class ExportDB {public static void main(String[] args) {//默认读取hibernate.cfg.xml文件Configuration cfg = new Configuration().configure();SchemaExport export = new SchemaExport(cfg);export.create(true, true);}
}

  相关解决方案