Hibernate 与数据库的关系是ORM关系,对象映射数据库。那么如何通过对象对数据库进行各种对象的ddl与dml操作呢?数据库对象操作的
hibernate 与数据库的关系是orm关系,对象映射数据库。
那么如何通过对象对数据库进行各种对象的ddl与dml操作呢?
数据库对象操作的〈database-object ../〉+ SchemaExport
1、hibernate.cfg.xml
br />"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
......
lt;/hibernate-configuration>
2、lovejk.hbm.xml
br />"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
3、执行
public static void main(String[] args) throws Exception
{
//实例化Configuration,,这行代码默认加载hibernate.cfg.xml文件
Configuration conf = new Configuration().configure();
//以Configuration创建SessionFactory
SessionFactory sf = conf.buildSessionFactory();
// //创建SchemaExport对象
SchemaExport se = new SchemaExport(conf);
// //设置输出格式良好的SQL脚本
se.setFormat(true);
// //设置保存SQL脚本的文件名
se.setOutputFile("d:\1.sql");
// //输出SQL脚本,并执行SQL脚本
se.create(true, true);
sf.close();
}
总结:简单粗暴!
Hibernate 的详细介绍:请点这里
Hibernate 的下载地址:请点这里
Hibernate 中文手册 PDF

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号