Java Reference
In-Depth Information
To sum up, there are three classes that you need to use: Configuration , SessionFactory ,
and Session .
Use the Configuration class to read (and to set) configuration details.
Use the Configuration object to create a SessionFactory object.
Use the SessionFactory object to create Session objects as needed.
A typical application will have one Configuration object, which will only be used in
initialization. There will be one SessionFactory object that will exist throughout the life
cycle of the application. Your application will ask this SessionFactory object for a Session
any time it needs to work with the database. The application could retrieve an object, make
some property changes, and then persist it, all within one session, and then close down the
Session object.
Hibernate Properties
Typically, you will specify your Hibernate configuration in a properties file called hibernate.
properties in the root directory of your application's classpath, or as identified values in a
hibernate.cfg.xml file. Hibernate has an extensive list of properties for configuration (see
Table 2-1).
Unless you provide a JDBC connection programmatically in your application, you must
either configure a JDBC connection here or specify the JNDI name of a container-provided
JDBC connection. You must also configure the SQL dialect appropriate to the database that
you are using. All the other properties take sensible default values, so they do not need to be
explicitly stated.
Table 2-1. Hibernate Configuration Property Names and Descriptions
Property Name
Description
hibernate.c3p0.acquire_increment
After the connection pool is completely utilized, deter-
mines how many new connections are added to the
pool.
hibernate.c3p0.idle_test_period
Determines how long to wait before a connection is
validated.
hibernate.c3p0.max_size
The maximum size of the connection pool for C3PO.
hibernate.c3p0.max_statements
The upper limit for the SQL statement cache for C3PO.
hibernate.c3p0.min_size
The minimum size of the connection pool for C3PO.
hibernate.c3p0.timeout
The timeout for C3PO (in seconds).
hibernate.cache.provider_class
Specifies a class that implements the org.hibernate.
cache.CacheProvider interface.
hibernate.cache.query_cache_factory
Specifies a class that implements the org.hibernate.
cache.QueryCacheFactory interface for getting
QueryCache objects.
hibernate.cache.region_prefix
The prefix to use for the name of the cache.
hibernate.cache.use_minimal_puts
Configures the cache to favor minimal puts over mini-
mal gets.
hibernate.cache.use_query_cache
Specifies whether to use the query cache.
Search WWH ::




Custom Search