The Hibernate MBean


The Hibernate archive instantiates and configures a Hibernate MBean (org.jboss.hibernate.jmx.Hibernate) that will be responsible for constructing a Hibernate SessionFactory and exposing it to your application through JNDI. In addition, the Hibernate MBean allows you to inspect and change the configuration of the SessionFactory at runtime.

In its most basic configuration, the Hibernate MBean simply needs to know the database name and dialect as well as where to bind the SessionFactory in the JNDI TRee. The following sample Hibernate MBean configuration illustrates a typical minimal Hibernate configuration:

[View full width]

<mbean code="org.jboss.hibernate.jmx.Hibernate"name="jboss.har:service=Hibernate"> <attribute name="DatasourceName">java:/DefaultDS</attribute> <attribute name="Dialect">net.sf.hibernate.dialect.HSQLDialect</attribute> <attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute> <attribute name="CacheProviderClass">net.sf.hibernate.cache.HashtableCacheProvider< /attribute> </mbean>

The following attributes are shown in this configuration:

  • DatasourceName This is the JNDI name of the datasource that Hibernate should use.

  • Dialect This is the SQL dialect (database type) for the database being used. Any valid Hibernate dialect may be used. The following are a few the more commonly used dialects:

     net.sf.hibernate.dialect.HSQLDialect net.sf.hibernate.dialect.Oracle9Dialect net.sf.hibernate.dialect.MySQLDialect net.sf.hibernate.dialect.SQLServerDialect net.sf.hibernate.dialect.FirebirdDialect 

  • SessionFactoryName This is the name of the JNDI where the constructed SessionFactory should be bound. Here we've chosen java:/hibernate/SessionFactory SessionFactory. If you are deploying multiple Hibernate applications in the JBoss Release 1 439 server, make sure to choose a unique name.

This really is a small Hibernate configuration. There are many more configuration options available. The following are a few of the more useful options:

  • Hbm2ddlAuto This option controls the automatic creation of tables for Hibernate objects. The valid values are create, create-drop, and update.

  • DefaultSchema This option sets a schema or tablespace name used to qualify unqualified tablenames in generated SQL.

  • ShowSqlEnabled Setting this option to true enables logging of SQL to the console.

  • CacheProviderClass This option sets the second-level cache provider.

  • DeployedTreeCacheJndiName This sets the JNDI name of the JBossTreeCache instance to use if using the DeployedTreeCacheProvider.

  • SessionFactoryInterceptor This sets the Interceptor on the configuration.

A full set of Hibernate configuration properties is available on the Hibernate MBean. Table 13.1 shows all the MBean properties that map to standard Hibernate configuration properties. For more information on the Hibernate configuration, see the Hibernate documentation or Hibernate in Action (Manning, 2004).

Table 13.1. Hibernate MBean Configuration Properties and Their Corresponding Property Names

MBean Property

Standard Hibernate Property

BatchVersionedDataEnabled

hibernate.jdbc.batch_versioned_data

CacheProviderClass

hibernate.cache.provider_class

CacheRegionPrefix

hibernate.cache.region_prefix

DatasourceName

hibernate.connection.datasource

DefaultSchema

hibernate.default_schema

Dialect

hibernate.dialect

GeneratedKeysEnabled

hibernate .jdbc.use_get_generated_keys

Hbm2ddlAuto

hibernate.hbm2ddl.auto

JdbcBatchSize

hibernate.jdbc.batch_size

JdbcFetchSize

hibernate.jdbc.fetch_size

JdbcScrollableResultSetEnabled

hibernate .jdbc.use_scrollable_resultset

MaxFetchDepth

hibernate.max_fetch_depth

MinimalPutsEnabled

hibernate.cache.use_minimal_puts

Password

hibernate.connection.password

QueryCacheEnabled

hibernate.cache.use_query_cache

QuerySubstitutions

hibernate.query.substitutions

ReflectionOptimizationEnabled

hibernate .cglib.use_reflection_optimizer

SessionFactoryName

hibernate.session_factory_name

ShowSqlEnabled

hibernate.show_sql

StreamsForBinaryEnabled

hibernate .jdbc.use_streams_for_binary

Username

hibernate.connection.username




JBoss 4. 0(c) The Official Guide
JBoss 4.0 - The Official Guide
ISBN: B003D7JU58
EAN: N/A
Year: 2006
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net