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

Hibernate Archives

JBoss provides a new, simplified way to package and deploy Hibernate applications. JBoss introduces the notion of a HAR file. The HAR file allows you to provide Hibernate objects to your application code without performing any of the tedious manual configuration or setup code normally required.

Structurally, a HAR file resembles a JBoss SAR file. The HAR file contains the Hibernate class files and mapping files, along with a hibernate-service.xml deployment descriptor in the META-INF directory. We'll look first at the hibernate-service.xml file.

The hibernate-service.xml file is actually just a normal jboss-service.xml file. The name is different, but the content is the same. The file should contain a definition for the Hibernate MBean (see the section "The Hibernate MBean," earlier in this chapter) configured correctly for the needs of the Hibernate application being created. The following example shows a typical hibernate-service.xml file:


<server>
    <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/CaveatEmptorSessionFactory<
/attribute>
        <attribute name="CacheProviderClass">net.sf.hibernate.cache.HashtableCacheProvider<
/attribute>
        <attribute name="Hbm2ddlAuto">create-drop</attribute>
        <attribute name="ShowSqlEnabled">true</attribute>
    </mbean>
</server>

Notice that the hibernate-service.xml file does not contain a list of the classes Hibernate is to map the way a hibernate.cfg.xml file would, and you do not need to manually add the Hibernate mapping files to the configuration the way you would when using a hibernate.properties file. Instead, the Hibernate deployer in JBoss scans the archive for .hbm.xml mapping files at deployment time and adds them to the configuration for you. Figure 13.1 shows the layout of a typical HAR file.

Figure 13.1. The structure of a typical HAR file.


The Hibernate deployer creates a configuration, using all the .hbm.xml files in the archive, and binds a Hibernate SessionFactory into the JNDI tree at the appropriate location. The SessionFactory can then be used by any application in JBoss. This example comes from the CaveatEmptor demo (http://caveatemptor.hibernate.org/). The CaveatEmptor code is provided along with the examples in this book. To deploy the Hibernate portion of the demo as a HAR file, you run the following command:

[examples]$ ant -Dchap=hibernate -Dex=1 run-example
...
[copy] Copying 1 file to /tmp/jboss-4.0.1/server/default/deploy

This creates and deploys the HAR file shown in Figure 13.1. If you look at the console log, you will see the Hibernate classes located and deployed as well as the results of the schema generation.