Hibernate的学习(创建配置文件hibernate.cfg.xml)
2017-03-08 21:55
411 查看
Hibernate配置文件主要用于配置数据库连接和Hibernate运行时所需的各种特性。
在工程的src目录下添加Hibernate配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 配置连接数据库的基本信息 -->
<!--这里是mysql数据库-->
<property name="connection.username">root</property>
<property name="connection.password">bdqn</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<!-- 配置 hibernate 的基本信息 -->
<!-- hibernate 所使用的数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 执行操作时是否在控制台打印 SQL -->
<property name="show_sql">true</property>
<!-- 是否对 SQL 进行格式化 -->
<property name="format_sql">true</property>
<!-- 指定自动生成数据表的策略 -->
<property name="hbm2ddl.auto">update</property>
<!-- 指定关联的 .hbm.xml 文件 -->
<mapping resource="com/java/hibernate/Dept.hbm.xml"/>
<mapping resource="com/java/hibernate/Emp.hbm.xml"/>
</session-factory>
</hibernate-configuration>
其中的几个常用的参数作用:
1connection.url:表示数据库URL。oracle数据库的URL是:jdbc:oracle:thin:@10.0.0.176:1521:orcl。(jdbc:oracle:thin:@是固定写法,10.0.0.176是IP地址,1521是端口号)
2connection.password是数据库用户密码
3connection.username数据库用户名
4current_session_context_class指定currentSession()方法所得到的Session由谁来跟踪管理,thread指Session由当前线程来跟踪管理。
5show_sql参数为true,则程序运行时在控制台输出SQL语句
6format_sql:参数为true,则程序运行时在控制台输出格式化后的SQL语句
在工程的src目录下添加Hibernate配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 配置连接数据库的基本信息 -->
<!--这里是mysql数据库-->
<property name="connection.username">root</property>
<property name="connection.password">bdqn</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<!-- 配置 hibernate 的基本信息 -->
<!-- hibernate 所使用的数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 执行操作时是否在控制台打印 SQL -->
<property name="show_sql">true</property>
<!-- 是否对 SQL 进行格式化 -->
<property name="format_sql">true</property>
<!-- 指定自动生成数据表的策略 -->
<property name="hbm2ddl.auto">update</property>
<!-- 指定关联的 .hbm.xml 文件 -->
<mapping resource="com/java/hibernate/Dept.hbm.xml"/>
<mapping resource="com/java/hibernate/Emp.hbm.xml"/>
</session-factory>
</hibernate-configuration>
其中的几个常用的参数作用:
1connection.url:表示数据库URL。oracle数据库的URL是:jdbc:oracle:thin:@10.0.0.176:1521:orcl。(jdbc:oracle:thin:@是固定写法,10.0.0.176是IP地址,1521是端口号)
2connection.password是数据库用户密码
3connection.username数据库用户名
4current_session_context_class指定currentSession()方法所得到的Session由谁来跟踪管理,thread指Session由当前线程来跟踪管理。
5show_sql参数为true,则程序运行时在控制台输出SQL语句
6format_sql:参数为true,则程序运行时在控制台输出格式化后的SQL语句
相关文章推荐
- hibernate学习的那些事之核心配置文件--hibernate.cfg.xml
- Hibernate学习-08:配置-核心配置文件hibernate.cfg.xml、映射文件*.hbm.xml
- hibernate3 学习笔记(二) hibernate 的配置文件 hibernate.cfg.xml
- Hibernate学习之配置文件hibernate.cfg.xml
- hibernate学习(一)hibernate.cfg.xml文件连接mySql、Oracle、SqlServer配置
- Hibernate配置文件创建及解析,hibernate.cfg.xml----Hibernate_0
- hibernate配置文件--hibernate.cfg.xml
- hibernate配置文件hibernate.cfg.xml的详细解释
- Hibernate.cfg.xml配置文件
- Hibernate连接SQL Server2008时候hibernate.cfg.xml和table.hbm.xml文件的配置详情
- 关于SSH框架配置文件 Hibernate.cfg.xml 、struts.xml、spring.xml
- Hibernate.cfg.xml配置文件解析
- Hibernate.cfg.xml配置文件模板及解析
- Hibernate配置文件模板(.cfg.xml)
- hibernate.cfg.xml文件的配置
- Hibernate动态建表,通过hbm.xml配置文件创建数据表,进行数据库操作, 动态模型
- hibernate学习笔记(一)---------hibernate.cfg.xml文件的具体配置
- Hibernate配置文件模板(.cfg.xml)
- Hibernate学习之hibernate.cfg.xml配置
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明