More Books
JBoss 4.0 The Official Guide
JBoss® 4.0 The Official Guide
Table of Contents
Copyright
About the Authors
We Want to Hear from You!
Introduction
What This Book Covers
About JBoss
About Open Source
About Professional Open Source
What's New in JBoss 4.0
Chapter 1.  Installing and Building the JBoss Server
Getting the Binary Files
Installing the Binary Package
Basic Installation Testing
Booting from a Network Server
Building the Server from Source Code
Chapter 2.  The JBoss JMX Microkernel
JMX
The JBoss JMX Implementation Architecture
Connecting to the JMX Server
Using JMX as a Microkernel
The JBoss Deployer Architecture
Exposing MBean Events via SNMP
Remote Access to Services, Detached Invokers
Chapter 3.  Naming on JBoss
An Overview of JNDI
The JBossNS Architecture
Chapter 4.  Transactions on JBoss
Transaction and JTA Overview
JBoss Transaction Internals
Chapter 5.  EJBs on JBoss
The EJB Client-Side View
The EJB Server-Side View
The EJB Container
Entity Bean Locking and Deadlock Detection
Chapter 6.  Messaging on JBoss
JMS Examples
JBossMQ Overview
JBossMQ Configuration and MBeans
Specifying the MDB JMS Provider
Chapter 7.  Connectors on JBoss
JCA Overview
An Overview of the JBossCX Architecture
Configuring JDBC Datasources
Configuring Generic JCA Adaptors
Chapter 8.  Security on JBoss
J2EE Declarative Security Overview
An Introduction to JAAS
The JBoss Security Model
The JBossSX Architecture
The Secure Remote Password (SRP) Protocol
Running JBoss with a Java 2 Security Manager
Using SSL with JBoss and JSSE
Configuring JBoss for Use Behind a Firewall
Securing the JBoss Server
Chapter 9.  Web Applications
The Tomcat Service
The Tomcat server.xml File
The Engine Element
The Host Element
Using SSL with the JBoss/Tomcat Bundle
Setting the Context Root of a Web Application
Setting Up Virtual Hosts
Serving Static Content
Using Apache with Tomcat
Using Clustering
Integrating Third-Party Servlet Containers
Chapter 10.  MBean Services Miscellany
System Properties Management
Property Editor Management
Services Binding Management
Scheduling Tasks
The Log4j Service MBean
RMI Dynamic Class Loading
Chapter 11.  The CMP Engine
Example Code
The jbosscmp-jdbc Structure
Entity Beans
CMP Fields
Container-Managed Relationships
Declaring Queries
Optimized Loading
The Loading Process
Transactions
Optimistic Locking
Entity Commands and Primary Key Generation
JBoss Global Defaults
Datasource Customization
Chapter 12.  Web Services
JAX-RPC Service Endpoints
Enterprise JavaBean Endpoints
Web Services ClientsA JAX-RPC Client
Service References
Chapter 13.  Hibernate
The Hibernate MBean
Hibernate Archives
Using Hibernate Objects
Using a HAR File Inside an EAR File
The HAR Deployer
Chapter 14.  Aspect-Oriented Programming (AOP) Support
JBoss AOP: EJB-Style Services for Plain Java Objects
Why AOP?
Basic Concepts of AOP
Building JBoss AOP Applications
The JBoss AOP Deployer
Packaging and Deploying AOP Applications to JBoss
Appendix A.  The GNU Lesser General Public License (LGPL)
GNU General Public License
Appendix B.  Example Installation
Index
SYMBOL
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X

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:


<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