3. Hibernate 环境配置
本部分描述如何配置Hibernate的开发环境,包括工程搭建、配置文件、配置方法和参数。
3.1. Hibernate工程搭建
要使用Hibernate进行开发,需要先搭建环境。以下两种方法均可完成搭建环境:
创建好项目之后,在/lib 目录下导入hibernate的核心jar包以及hibernatexxxdialect.jar方言包。
使用Maven工具来管理jar包,修改pom.xml配置来导入hibernate核心jar包以及hibernatexxxdialect.jar方言包。
3.2. Hibernate的配置文件说明
定义 hibernate 配置文件,根据用户选择更改以下配置文件。
在hibernate.properties 中增加如下声明:
hibernate.dialect org.hibernate.dialect.Kingbase8Dialect
在hibernate.cfg.xml 中增加如下声明:
<property name="dialect">org.hibernate.dialect.
Kingbase8Dialect</property>
在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" 等参数。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




