现在的位置: 首页 > 综合 > 正文

Hbernate的主配置文件hibernate.cfg.xml

2017年11月30日 ⁄ 综合 ⁄ 共 1505字 ⁄ 字号 评论关闭

hibernate.cfg.xml存放在src目录下,在添加Myeclipse对Hibernate的支持时可选择是否自动生成,也可手动添加。

<?xmlversion='1.0'encoding='UTF-8'?>

<!DOCTYPEhibernate-configuration(根元素)PUBLIC

          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

   <session-factory>

        <propertyname="connection.url">jdbc:mysql://localhost:3306/hibernate(操纵的是hibernate数据库)</property>

        <propertyname="connection.username">root</property>

        <propertyname="connection.password">qiang</property>

        <propertyname="connection.driver_class">com.mysql.jdbc.Driver</property>

       <propertyname="dialect">org.hibernate.dialect.MySQL5Dialect</property>(方言)

   

        <propertyname="show_sql">true</property>(是否显示SQL语句,因为我们会通过hibernate操纵SQL语句)

       

        <mappingresource="Person.hbm.xml"/>(指定对象关系映射文件)

   </session-factory>

</hibernate-configuration>

说明:

hibernate.dialect:指定数据库使用的SQL方言;(可以到hibernate API中查询)

hibernate.connection.url:指定连接的url

hibernate.connection.username:指定连接数据库的用户名

hibernate.connection.password:指定连接数据库的口令

hibernate.connection.driver_class:指定数据库的驱动程序

hibernate.show_sql:指定是否在控制台输出SQL语句,默认为false,在开发阶段最好设置为true以便跟踪Hibernate的运行状态和调试应用程序;在应用发布阶段应将其设

为 false以减少语句输出,提高运行时的性能。

(上述name="show_sql"可省略hibernate,也可name="hibernate.show_sql"

<mappingresource="Person.hbm.xml"/>指定了针对于Person类的映射文件,若有多个映射文件,可用多个<mapping>指定。所有的对象关系映射文件都要在hibernate.cfg.xml文件中用<mapping>指定,也正是这样,Hibernate才会知道类和表的映射关系。

转载请注明出处:http://blog.csdn.net/jialinqiang/article/details/8669660

抱歉!评论已关闭.