Hibernate之配置文件

在上一篇博客中我已经说明了jar包的下载,jar中提供给了我们很多关于hibernate的配置信息,这里主要说明几样平常项目常用的. 进入源码包. 1.连接数据库四要素## MySQL#hibernate.dialect org.hibernate.dialect.MySQLDialect#hibernate.dialect org.hibernate.diale...
摘要由CSDN通过智能技术生成

在上一篇博客中我已经说明了jar包的下载,jar中提供给了我们很多关于hibernate的配置信息,这里主要说明几样平常项目常用的.
这里写图片描述

进入源码包

这里写图片描述

.
这里写图片描述

1.连接数据库四要素

## MySQL

#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///test
#hibernate.connection.username gavin
#hibernate.connection.password

2.配置数据源

若不使用第三方数据源,则使用默认配置数据源

#hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.ProxoolConnectionProvider

3.配置当前Session的上下文

指定当前session为上下文,(同一线程内使用的session为同一Session)

<!-- session -->
    <property name="hibernate.current_session_context_class">thread</property>

4.自动建表

<!-- 自动建表 -->
    <property name="hibernate.hbm2ddl.auto">true</property>

5.SQL语句显示在控制台

 <!-- 显示SQL语句-->
    <property name="show_sql">true</property>
    <!-- 显示语句格式 -->
    <property name="format_sql">true</property>

6.注册映射文件

<mapping resource="com/xxx/User.hbm.xml" />

=========hibernate.properties============

#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
#

######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions yes 'Y', no 'N'


## select the classic query parser

#hibernate.query.factory_class org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory



#################
### Platforms ###
#################

## JNDI Datasource

#hibernate.connection.datasource jdbc/test
#hibernate.connection.username db2
#hibernate.connection.password db2


## HypersonicSQL

hibernate.dialect org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class org.hsqldb.jdbcDriver
hibernate.connection.username sa
hibernate.connection.password
hibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate
#hibernate.connection.url jdbc:hsqldb:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test

## H2 (www.h2database.com)
#hibernate.dialect org.hibernate.dialect.H2Dialect
#hibernate.connection.driver_class org.h2.Driver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:h2:mem:./build/db/h2/hibernate
#hibernate.connection.url jdbc:h2:testdb/h2test
#hibernate.connection.url jdbc:h2:mem:imdb1
#hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample;     
#hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample;     
#hibernate.connection.url jdbc:h2:ssl://secureserv/testd
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值