您的位置:首页 > 其它

hibernate.cfg.xml的配置

2016-09-17 14:33 411 查看

hibernate.cfg.xml的配置

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- 1、配置数据库连接信息
支持jdbc
连接池
-->
<!-- 数据库驱动 -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- 连接url
jdbc:mysql:///hibernate4
相当于下面的
-->
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate4?useUnicode=true&characterEncoding=utf-8
</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<!-- 2、hibernate可选项信息 -->
<!-- 数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 配置是否打印sql语句 -->
<property name="show_sql">true</property>
<!-- 格式化sql语句 -->
<property name="format_sql">true</property>
<!-- 数据库的更新方法
create:每次执行都先把原有数据表删掉,然后创建该表
create-drop:在显示关闭SessionFactory时删除对应的数据表
validate:检测存在与否
update:发现没有表的时候创建表,如果有就不用创建
-->
<property name="hbm2ddl.auto">update</property>
<!-- 3、映射文件信息 -->
<mapping resource="com/pojo/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate