Hibernate根据映射文件生成数据库表

Javaxy Javaxy 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package com.xy.HibernateUtil;

import org.hibernate.cfg.Configuration;

import java.io.File;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class ExportDB {

static Session session;

static Configuration config = null;
static Transaction tx = null;

public static void main(String[] args) {
/** *//** *//** *//**
* 根据映射文件创建数据库结构
*/
try{
config = new Configuration().configure(new File(
"src/hibernate.cfg.xml"));

System.out.println("Creating tables...");

SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
tx = session.beginTransaction();

SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);

System.out.println("Table created.");

tx.commit();

} catch (HibernateException e) {
e.printStackTrace();
try{
tx.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}
} finally {
session.close();
}
}

}
通过这个类生成数据库的表,为什么明明显示执行了两条CREATE语句,生成了两个表,但是在数据库中只生成了一个表啊?
...全文
评论 7
收藏 已收藏
分享
返回顶部
Javaxy
Java EE 67,535 成员 225,843 内容