Hibernate笔记 - Hibernate在项目中的使用和基本和配置

发布于 2011-07-16 | 更新于 2020-09-20

1、搭建Hibernate的环境:

新建一个User Library:Hibernate 3,引入jar文件:

HIBERNATE_HOME\lib 下的相关的依赖的第三方包 HIBERNATE_HOME/hibernate3.jar Hibernate的核心实现 引入相关的JDBC驱动

把创建的Hibernate用户库引进项目中。

2、在项目中的SRC目录下创建相关的配置文件:

HIBERNATE_HOME \etc\ hibernate.properties 旧版本的Hibernate实用的核心配置文件,这个文件列举了相关的Hibernate配置,在配置文件时可以参考该文件。

HIBERNATE_HOME \etc\ hibernate.cfg.xml 如果存在这个文件则会覆盖上面的properties文件。

HIBERNATE_HOME\hibernate-3.2\etc 日志记录文件。

3、编写hibernate.cfg.xml文件:

com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/test_1 root abc org.hibernate.dialect.MySQLDialect true

4、映射实体类的xml配置基本格式如下:

创建完映射文件之后,记得把hbm.xml文件添加到hibernate.cfg.xml文件中

在session-factory标签里property标签后。

5、使用SchemaExport生成数据库:

Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
// 创建hibernate.cfg.xml文件中指定的test_1数据库,并使用该数据库,然后运行上面的代码

本文作者: arthinking

本文链接: https://www.itzhai.comthe-hibernate-notes-the-hibernate-in-the-project-use-and-basic-configuration.html

版权声明: 版权归作者所有,未经许可不得转载,侵权必究!联系作者请加公众号。

IT宅

关注公众号及时获取网站内容更新。