金仓数据库KingbaseES客户端编程开发框架-Hibernate(3. Hibernate 环境配置)

栏目归类:人大金仓数据库
发布时间:2024-03-26 18:54:19

3.?Hibernate 环境配置

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

3.1.?Hibernate工程搭建

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

  • 创建好项目之后,在/lib 目录下导入hibernate的核心jar包以及hibernatexxxdialect.jar方言包。

  • 使用Maven工具来管理jar包,修改pom.xml配置来导入hibernate核心jar包以及hibernatexxxdialect.jar方言包。

3.2.?Hibernate的配置文件说明

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

  1. 在hibernate.properties 中增加如下声明:

hibernate.dialect org.hibernate.dialect.Kingbase8Dialect
  1. 在hibernate.cfg.xml 中增加如下声明:

<property name="dialect">org.hibernate.dialect.
    Kingbase8Dialect</property>
  1. 在persistence.xml 中增加如下声明:

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

注意

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

3.3.?服务的配置方法和参数说明

Hibernate配置文件示例

<?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" 等参数。

文章来源:https://blog.csdn.net/arthemis_14/article/details/126888243
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
Feichi 技术分享站