JBoss EJB 3.0
JBoss EJB 3.0 Reference Documentation
RC7 - PFD
Table of Contents
Preface ............................................................................................................................................iv
1. Session EJB and MDB Configuration .............................................................................................1
1.1. Pooling ..............................................................................................................................1
1.2. The Stateful Session Bean Cache ........................................................................................2
1.2.1. Non-Clustered .........................................................................................................2
1.2.2. Clustered ................................................................................................................3
1.2.3. No Passivation ........................................................................................................3
2. References and Injection XML and Annotations ............................................................................. 4
2.1. Intro ..................................................................................................................................4
2.2. EJB references ...................................................................................................................4
3. @Resource Annotation ................................................................................................................. 5
4. Entity Configuration Files .............................................................................................................6
4.1. Intro ..................................................................................................................................6
4.2. Configuration Files .............................................................................................................6
4.2.1. Configure JBoss datasource ..................................................................................... 6
4.2.2. persistence.xml and .jar files .................................................................................... 6
4.3. EAR and WAR files ...........................................................................................................8
4.4. Referencing persistence units .............................................................................................. 8
4.4.1. Scoped deployments ................................................................................................8
4.4.2. Referencing from Global JNDI ................................................................................. 8
4.5. Securing Entity Beans ........................................................................................................8
5. Hibernate Integration .................................................................................................................. 11
5.1. Hibernate Mapping Files ................................................................................................... 11
5.2. Injection Hibernate Session and SessionFactory ................................................................. 11
5.3. Access to org.hibernate.Session ......................................................................................... 11
5.4. Access to org.hibernate.Query ........................................................................................... 12
6. JBoss EJB 3.0 extensions ............................................................................................................ 13
6.1. @Service EJBs ................................................................................................................ 13
6.1.1. @org.jboss.annotation.ejb.Management interface .................................................... 13
6.1.2. Lifecycle Management and dependencies ................................................................ 13
6.1.2.1. Lifecycle Methods ...................................................................................... 13
6.1.2.2. Dependencies ............................................................................................. 14
6.1.3. Example ............................................................................................................... 14
6.2. Message Driven POJOs .................................................................................................... 16
6.3. Asynchronous invocations ................................................................................................ 16
7. JBoss EJB 3.0 jboss.xml deployment descriptor ............................................................................ 19
7.1. Bean extensions ............................................................................................................... 19
7.1.1. Service ................................................................................................................. 19
7.1.2. Consumer/Producer ............................................................................................... 22
8. JBoss EJB 3.0 partial deployment descriptors ............................................................................... 24
8.1. Overview ......................................................................................................................... 24
8.2. Examples ......................................................................................................................... 24
8.2.1. Complete deployment descriptor ............................................................................ 24
8.2.2. Security ................................................................................................................ 26
8.2.3. Transactions .......................................................................................................... 27
8.2.4. References ............................................................................................................ 27
8.2.5. Callbacks .............................................................................................................. 27
9. JBoss EJB 3.0 MDB JCA Inflow ................................................................................................. 28
JBoss RC7 - PFD ii
9.1. SwiftMQ JCA XA Resource ............................................................................................. 28
9.2. Non-Standard Messaging Types ........................................................................................ 28
10. Transports ................................................................................................................................ 30
10.1. Default transport ............................................................................................................ 30
10.2. Securing the transport ..................................................................................................... 30
10.2.1. Generating the keystore and truststore ................................................................... 30
10.2.2. Setting up the SSL transport ................................................................................. 31
10.2.3. Configuring your beans to use the SSL transport .................................................... 32
10.2.4. Setting up the client to use the truststore ................................................................ 32
JBoss EJB 3.0
JBoss RC7 - PFD iii
Preface
This isn't the only reference to learn EJB 3.0 Look in the JBoss EJB 3.0 tutorial for loads of example programs
and detailed text describing each example.
In some of the example listings, what is meant to be displayed on one line does not fit inside the available page
width. These lines have been broken up. A '\' at the end of a line means that a break has been introduced to fit in
the page, with the following lines indented. So:
Let's pretend to have an extremely \
long line that \
does not fit
This one is short
Is really:
Let's pretend to have an extremely long line that does not fit
This one is short
JBoss RC7 - PFD iv
1
Session EJB and MDB Configuration
1.1. Pooling
Both Stateless Session beans and Message Driven Beans have an instance pool. The basic configuration of
JBoss uses a thread local pool to avoid Java synchronization (org.jboss.ejb3.ThreadLocalPool). These EJB
types can be configured to use an alternative pooling mechanism. For example, JBoss has a strict pool size im-
plementation that will only allow a fixed number of concurrent requests to run at one time. If there are more re-
quests running than the pool's strict size, those requests will block until an instance becomes available. This is
configured via the @org.jboss.annotation.ejb.PoolClass annotation.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface PoolClass
{
Class value();
int maxSize() default 30;
long timeout()default Long.MAX_VALUE;
}
The value() parameter defines the pool implementation class you want to plug in. maxSize() defines the size of
the pool while timeout() is a time in milliseconds you want to block when waiting for an instance to be ready.
This annotation can be applied to a stateless or message driven bean class. Here's an example of using it.
@Stateless
@PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=5, timeout=10000)
@Remote(StrictlyPooledSession.class)
public class StrictlyPooledSessionBean implements StrictlyPooledSession
{
...
}
There is no nice way of applying the same configuration through XML. To do it through XML you must define
a new aspect domain (an EJB container configuration template) and define an annotation override within that
domain and then apply the domain through jboss.xml. Here's an example:
First create the aspect domain. Create a file called mydomain-aop.xml and put this in the top level directory of
your EJB jar. Might seem a little cryptic but what this is doing is declaring an annotation that will be created by
the EJB container. Our EJB3 implementation is based on JBoss AOP. See the JBoss AOP documentation for
more info on annotation overrides.
<aop>
<domain name="Strictly Pooled Stateless Bean" extends="Stateless Bean" inheritBindings="true">
<annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
@org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=5, timeout=10000)
</annotation>
JBoss RC7 - PFD 1
评论1