hibernate配置MySQL参数_Hibernate配置

Hibernate要求预先知道在哪里可以找到它定义Java类是如何关联到数据库表的映射信息。 Hibernate也需要一组相关的数据库和其他相关参数的配置设置。所有这些信息通常是hibernate.properties,一个标准的Java属性文件,或者作为一个名为hibernate.cfg.xml的XML文件。

考虑XML格式的文件hibernate.cfg.xml中指定在例子必需的Hibernate属性。大部分的属性取默认值,它不需要在属性文件中指定它们,除非它真的是必需的。此文件保存在应用程序的类路径的根目录。

Hibernate 属性:

以下是需要在独立情况下配置一个数据库的重要属性的列表:

S.N.

属性和说明

1

hibernate.dialect

This property makes Hibernate generate the appropriate SQL for the chosen database.

2

hibernate.connection.driver_class

The JDBC driver class.

3

hibernate.connection.url

The JDBC URL to the database instance.

4

hibernate.connection.username

The database username.

5

hibernate.connection.password

The database password.

6

hibernate.connection.pool_size

Limits the number of connections waiting in the Hibernate database connection pool.

7

hibernate.connection.autocommit

Allows autocommit mode to be used for the JDBC connection.

如果是随着应用程序服务器和JNDI使用一个数据库,那么就必须配置以下属性:

S.N.

属性和说明

1

hibernate.connection.datasource

The JNDI name defined in the application server context you are using for the application.

2

hibernate.jndi.class

The InitialContext class for JNDI.

3

hibernate.jndi.

Passes any JNDI property you like to the JNDI InitialContext.

4

hibernate.jndi.url

Provides the URL for JNDI.

5

hibernate.connection.username

The database username.

6

hibernate.connection.password

The database password.

Hibernate和MySQL数据库:

MySQL是最受欢迎的开源数据库系统之一。让我们创建hibernate.cfg.xml配置文件,并将其放置在应用程序的类的根路径。必须确保有MySQL数据库可供TESTDB数据库,必须提供一个用户test来访问数据库。

XML配置文件必须符合Hibernate 3配置的DTD,可从 http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd.

<?xml version="1.0"encoding="utf-8"?>/p>

"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">org.hibernate.dialect.MySQLDialectcom.mysql.jdbc.Driverjdbc:mysql://localhost/testrootroot123

上面的配置文件包含这都与hibernate映射文件标签,我们将在下一章看到到底什么是Hibernate映射文件,以及如何和为什么要使用它。以下是各种重要的数据库方言属性类型的列表:

Database

Dialect Property

DB2

org.hibernate.dialect.DB2Dialect

HSQLDB

org.hibernate.dialect.HSQLDialect

HypersonicSQL

org.hibernate.dialect.HSQLDialect

Informix

org.hibernate.dialect.InformixDialect

Ingres

org.hibernate.dialect.IngresDialect

Interbase

org.hibernate.dialect.InterbaseDialect

Microsoft SQL Server 2000

org.hibernate.dialect.SQLServerDialect

Microsoft SQL Server 2005

org.hibernate.dialect.SQLServer2005Dialect

Microsoft SQL Server 2008

org.hibernate.dialect.SQLServer2008Dialect

MySQL

org.hibernate.dialect.MySQLDialect

Oracle (any version)

org.hibernate.dialect.OracleDialect

Oracle 11g

org.hibernate.dialect.Oracle10gDialect

Oracle 10g

org.hibernate.dialect.Oracle10gDialect

Oracle 9i

org.hibernate.dialect.Oracle9iDialect

PostgreSQL

org.hibernate.dialect.PostgreSQLDialect

Progress

org.hibernate.dialect.ProgressDialect

SAP DB

org.hibernate.dialect.SAPDBDialect

Sybase

org.hibernate.dialect.SybaseDialect

Sybase Anywhere

org.hibernate.dialect.SybaseAnywhereDialect

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值