Hibernate 环境配置
========================

本部分描述如何配置Hibernate的开发环境，包括工程搭建、配置文件、配置方法和参数。

- Hibernate工程搭建_
- Hibernate的配置文件说明_
- 服务的配置方法和参数说明_

Hibernate工程搭建
--------------------

要使用Hibernate进行开发，需要先搭建环境。以下两种方法均可完成搭建环境：

- 创建好项目之后，在/lib 目录下导入hibernate的核心jar包以及hibernatexxxdialect.jar方言包。
- 使用Maven工具来管理jar包，修改pom.xml配置来导入hibernate核心jar包以及hibernatexxxdialect.jar方言包。

Hibernate的配置文件说明
-----------------------

定义 hibernate 配置文件，根据用户选择更改以下配置文件。

a. 在hibernate.properties 中增加如下声明：

  .. code:: PROGRAMLISTING

         hibernate.dialect = org.hibernate.dialect.Kingbase8Dialect

b. 在hibernate.cfg.xml 中增加如下声明：

  .. code:: PROGRAMLISTING

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

c. 在persistence.xml 中增加如下声明：

  .. code:: PROGRAMLISTING

         <property name="hibernate.dialect" 
             value="org.hibernate.dialect.Kingbase8Dialect" />

.. note::

     hibernatexxxdialect.jar 方言包全部依赖于1.6以上版本JDK生成。

服务的配置方法和参数说明
------------------------

Hibernate配置文件示例

  .. code:: PROGRAMLISTING

         <?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="hbm2ddl.auto">create-drop</property>
                 <property name="show_sql">true</property>
                 <property name="use_sql_comments">false</property>
                 <property name="dialect">org.hibernate.dialect.Kingbase8Dialect
                 </property>
                 <property name="connection.driver_class">com.kingbase8.Driver
                 </property>
                 <property name="connection.url">jdbc:kingbase8://localhost:54321/
                 test</property>
                 <property name="connection.username">test</property>
                 <property name="connection.password">test</property>
                 <mapping resource="hibernate_test.hbm.xml"/>
             </session-factory>
         </hibernate-configuration>

配置时按照实际使用情况修改 "dialect" 、 "connection.driver_class" 等参数。




 
 


 
 
 
 