Hibernate infrastructure Configuration

Source: Internet
Author: User
Tags connection pooling mysql database

Hibernate configuration files can have two formats, one is Hibernate.properties, the other is hibernate.cfg.xml the latter a little more convenient, when adding HBM mapping file, you can directly Hibernate.cfg.xml inside is added, not necessarily like hibernate.properties must be added in the initialization code.

But either way, the configuration items are the same, as described in detail below:

In the Hibernate src directory there is a hibernate.properties template, we do not have to write from scratch, modify the template on it:

Hibernate.query.substitutions true 1, false 0, yes ' Y ', no ' N '

This configuration means that when you enter true in Hibernate, Hibernate translates to 1 to insert the database, and when you enter False in Hibernate, Hibernate translates to 0 to insert the database, followed by the same y,n.

For some databases, such as Oracle, there is no Boolean data type, that is, 1 represents false true,0, so using this configuration in hibernate directly with True/false will be very intuitive.

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql:/**////test
hibernate.connection.username root
hibernate.connection.password
This is a connection to the MySQL database example, very intuitive, do not have to explain, the different database connection parameter template are all given.

Hibernate.connection.pool_size 1

Hibernate.statement_cache.size 25

This is the configuration parameter of the hibernate's own connection pool, which is to be used by default. The meaning is very intuitive, not many explanations.

Just to remind you that hibernate this connection pool is a very primitive and very simple connection pool, if you use Hibernate in the project, it is recommended that you prefer the connection pool of the app server, the secondary selection of the Hibernate band DBCP Connection pool. Your own connection pool should be the last choice.

If you are using a DBCP connection pool, in addition to configuring the DBCP connection pool, you need to cancel the comment that fell off the line:

Hibernate.connection.provider_class Net.sf.hibernate.connection.DBCPConnectionProvider

Other connection pooling is the same.

If you are using the connection pool of app server, assuming that the datasource Jndi name of the app server connection pool is called "Mypool", the configuration should be as follows:

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.datasource mypool
hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider

Other parameters will not have to be written because they are already specified when the app server configures the connection pool.

If you're not using hibernate in the app server environment, such as remote client programs, but you want to use app server's database connection pool, you'll also need to configure Jndi parameters, For example, hibernate connects to a database connection pool on a remote WebLogic:

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.datasource mypool
hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
hibernate.jndi.class weblogic.jndi.WLInitialContextFactory
hibernate.jndi.url t3://servername:7001/

Finally, if you need to use hibernate in EJB or JTA, you need to cancel the following comments:

Hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.