SchemaExport se=new SchemaExport(cfg).setOutputFile("xby.sql");
se.execute(true,true,false,false);
第一个true指导出sql文件,第二个true指执行数据库DDL.
public class HibernateUtils {
public static final Logger log=LoggerFactory.getLogger(HibernateUtils.class);
private static SessionFactory sf;
static{
try{
Configuration cfg=new Configuration().configure();
sf=cfg.buildSessionFactory();
SchemaExport se=new SchemaExport(cfg).setOutputFile("xby.sql");
se.execute(true,true,false,false);
}catch(Throwable e){
log.error("SessionFacotry init error-{}",e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory(){
return sf;
}
public static void shutDown(){
if(sf!=null){
sf.close();
}
}
}
hibernate创建导出数据库DDL schema,布布扣,bubuko.com