Hibernate配置属性

  • 内容
  • 评论
  • 相关

Hibernate 通过读取默认的配置文件来加载数据库配置信息,该配置文件应放于 classpath 根目录下,默认的配置文件名称为 Hibernate.cfg.xml。Hibernate.cfg.xml 文件中不仅包含数据库的配置信息,而且包含了用户对 Hibernate 所设置的属性信息,如打印 SQL 语句、自动建表等。其配置方法如下:

<?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>
    <!--数据库驱动-->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <!--数据库连接的URL-->
    <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
    <!--数据库连接用户名-->
    <property name="connection.username">root</property>
    <!--数据库连接密码-->
    <property name="connection.password">111</property>
    <!--Hibernate方言-->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <!--打印SQL语句-->
    <property name="show_sql">true</property>
    <!--映射文件-->
    <mapping resource="com/lyq/User.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

本文标题:Hibernate配置属性

本文地址:https://www.hosteonscn.com/6508.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注