使用Hibernate创建表结构

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)