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);}
}
详细解决方案
2.一对一单向主键关联(人对身份证) 工具类
热度:75 发布时间:2024-01-17 02:44:06.0
相关解决方案