zoukankan      html  css  js  c++  java
  • Hibernate 主配置文件详解

     

    一、数据库基本配置信息主要包括5项:数据库方言、数据库连接字符串、数据用户名、数据库密码、驱动 具体不同数据库的配置可以参考如下:

    二、其他信息主要包括3项:是否显示sql语句(showsql) 是否格式化sql语句(format_sql)及是否有Hibernate生成数据库创建脚本(DDL)

    三、导入一些对象与表的映射文件

    具体的配置样例如下:

     

    <!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>

           <!-- 一、数据库信息:数据库方言(是一个类的全名)与数据库连接信息 -->

           <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

           <property name="connection.url">jdbc:mysql:///hibernate_20120131</property>

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

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

           <property name="connection.password">root</property>

           <!-- 二、其他配置 -->

           <property name="show_sql">true</property>

           <property name="format_sql">false</property>

           <!--

               create: 先删表,再建表。

               create-drop: 启动时建表,退出前删表。

               update: 如果表结构不一致,就创建或更新。

               validate: 启动时验证表结构,如果不致就抛异常。

            -->

           <property name="hibernate.hbm2ddl.auto">update</property>

           <!-- 三、导入映射配置文件

           <mapping resource="cn/itcast/a_helloworld/User.hbm.xml"/>

            -->

        </session-factory>

    </hibernate-configuration>

  • 相关阅读:
    闭包Closures
    jsp中的四种对象作用域
    JFrame小练习1
    swift函数的用法,及其嵌套实例
    图的储存
    洛谷P3366 【模板】最小生成树(Kruskal && Prim)
    洛谷P3371 【模板】单源最短路径(弱化版)(SPFA解法)
    POJ 1577 Falling Leaves
    POJ 3784 Running Median
    洛谷P3374 【模板】树状数组 1
  • 原文地址:https://www.cnblogs.com/oftenlin/p/2988982.html
Copyright © 2011-2022 走看看