import java.io.File;
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 Test {
static Session session;
static Configuration config=null;
static Transaction tx=null;
public static void main(String[] args) throws Exception {
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();
}
}
使用Hibernate创建表结构
使用Hibernate创建数据库表
最新推荐文章于 2025-07-28 23:27:29 发布
本文介绍了如何使用Java和Hibernate框架创建数据库表,包括配置Hibernate、建立SessionFactory、打开Session、开始事务、执行SchemaExport创建表等步骤。
615

被折叠的 条评论
为什么被折叠?



