Programming Tutorials

Hibernate JDBC and Connection Properties

By: Felix in Hibernate Tutorials on 2010-12-29  

The table below lists the Hibernate JDBC and Connection Properties and their purpose. For easier understanding, and example is also provided for each property.
Property name Purpose
hibernate.jdbc.fetch_size A non-zero value determines the JDBC fetch size (callsStatement.setFetchSize()).
hibernate.jdbc.batch_size A non-zero value enables use of JDBC2 batch updates by Hibernate. 

e.g. recommended values between 5 and 30

hibernate.jdbc.batch_versioned_data Set this property to true if your JDBC driver returns correct row counts from executeBatch(). It is usually safe to turn this option on. Hibernate will then use batched DML for automatically versioned data. Defaults to false.

e.g. true | false

hibernate.jdbc.factory_class Select a custom org.hibernate.jdbc.Batcher. Most applications will not need this configuration property.

e.g. classname.of.BatcherFactory

hibernate.jdbc.use_scrollable_resultset Enables use of JDBC2 scrollable resultsets by Hibernate. This property is only necessary when using user-supplied JDBC connections. Hibernate uses connection metadata otherwise. 

e.g. true | false

hibernate.jdbc.use_streams_for_binary Use streams when writing/reading binary or serializabletypes to/from JDBC. *system-level property*

e.g. true | false

hibernate.jdbc.use_get_generated_keys Enables use of JDBC3 PreparedStatement.getGeneratedKeys()to retrieve natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+, set to false if your driver has problems with the Hibernate identifier generators. By default, it tries to determine the driver capabilities using connection metadata.

e.g. true|false

hibernate.connection.provider_class The classname of a customorg.hibernate.connection.ConnectionProvider which provides JDBC connections to Hibernate.

e.g. classname.of.ConnectionProvider

hibernate.connection.isolation Sets the JDBC transaction isolation level. Checkjava.sql.Connection for meaningful values, but note that most databases do not support all isolation levels and some define additional, non-standard isolations.

e.g. 1, 2, 4, 8

hibernate.connection.autocommit Enables autocommit for JDBC pooled connections (it is not recommended). 

e.g. true | false

hibernate.connection.release_mode Specifies when Hibernate should release JDBC connections. By default, a JDBC connection is held until the session is explicitly closed or disconnected. For an application server JTA datasource, use after_statement to aggressively release connections after every JDBC call. For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by using after_transaction. auto will choose after_statement for the JTA and CMT transaction strategies and after_transaction for the JDBC transaction strategy.

e.g. auto (default) | on_close | after_transaction |after_statement

This setting only affects Sessions returned fromSessionFactory.openSession. For Sessions obtained throughSessionFactory.getCurrentSession, the CurrentSessionContextimplementation configured for use controls the connection release mode for those Sessions.

hibernate.connection.<propertyName> Pass the JDBC property <propertyName> toDriverManager.getConnection().
hibernate.jndi.<propertyName> Pass the property <propertyName> to the JNDIInitialContextFactory.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)