EJB Bean Annotation
Resin 3.1

Documentation
Examples
Changes

Overview
Installation
Configuration
Quercus
SOA/IoC
JSP
Servlets and Filters
Admin (JMX)
EJB
Amber
Security
Performance
Hessian
XML and XSLT
Third-party
Troubleshooting/FAQ

Annotation
EJB
EJB
Amber

Session beans may be configured using dependency injection annotation.

Note These annotations will likely change package names to something other than javax.ejb as J2EE 1.5 drafts progress.

See Also

Bean Annotations

@Entity

Marks the class as an entity bean. Each entity bean corresponds to a database row. Entity bean persistence is configured with the Amber annotations.

In EJB 3.0, the application uses entity bean instances directly. Unlike EJB 2.1, there is no pooling, local stub, or home interface for an entity.

nameThe bean's nameThe bean's class name
entityTypecontainer-managed (CMP) or bean-managed (BMP)CMP
accessfield-based (FIELD) or method-getter based (PROPERTY)PROPERTY
versionEJB version3
@Target(TYPE) @Retention(RUNTIME) public @interface Entity { String name() default ""; EntityType entityType() default EntityType.CMP; AccessType access() default AccessType.PROPERTY; int version() default 3; }

@TransactionAttribute

Defines the transaction boundary for session business methods. The default value is REQUIRED. If @TransactionAttribute annotates the class, it defines the default value.

TransactionAttributemeaning
REQUIREDStart a new transaction if necessary
SUPPORTSDon't start a new transaction, but use one if it exists
MANDATORYRequire the caller to have started a transaction
NEVERForbid the caller to have started a transaction
REQUIRESNEWAlways start a new transaction, suspending the old one
NOTSUPPORTEDSuspend any active transaction
  • SUPPORTS is typically used for read-only methods
  • REQUIRED is typically used for updating (read/write) methods
@Target({TYPE,METHOD}) @Retention(RUNTIME) public @interface TransactionAttribute { TransactionAttributeType value() default REQUIRED; }

Dependency Injection Annotations

@EJB

Configures an EJB values for a field or method.

@EJB is essentially a @Resource where it's known that the result is an EJB interface.

jndiNameThe jndi name of the resourceThe field name

In the following exaple, Resin will call setFoo method with the bean in "java:comp/env/ejb/foo" before the session is started.

@EJB
void setFoo(example.Test test)
{
  _test = test;
}
javax.ejb.EJB
@Target({TYPE, METHOD, FIELD, PARAMETER}) @Retention(RUNTIME) public @interface EJB { String name() default ""; String businessInterface() default ""; String jndiName() default ""; }

@Inject

Configures a JNDI values for a field or method.

Inject relies heavily on defaults from the field or method name and type. If more information is required, use @Resource, @EJB, or @EJBHome.

jndiNameThe jndi name of the resourceThe field name

In the following exaple, Resin will call setDataSource method with the data source in "java:comp/env/jdbc/test" before the session is started.

@Inject(jndi-name="java:comp/env/jdbc/test")
void setDataSource(javax.sql.DataSource dataSource)
{
  _dataSource = dataSource;
}
javax.ejb.Inject
@Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Inject { String jndiName() default ""; }

@Resource

Configures a JNDI values for a field or method. @Resource is essentially the same as @Inject but provides more configurable options. @Resource can also be used at the Class level to declare a dependency in cases where the session bean loads the JNDI value by itself.

nameThe name of the resourceThe field name
resourceTypeThe resource typedThe field type
authenticationTypeWhether the container or the application is responsible for authenticationCONTAINER
shareableTrue if the bean follows JCA shareability requirements.true
jndiNameThe jndi name of the resourceThe field name

In the following exaple, Resin will call setDataSource method with the data source in "java:comp/env/jdbc/test" before the session is started. The "java:comp/env/jdbc" full name is inferred from the DataSource type.

default JNDI names
javax.sql.DataSourcejava:comp/env/jdbc
javax.mail.*java:comp/env/mail
javax.ejb.EntityManagerjava:comp/EntityManager
javax.transaction.UserTransactionjava:comp/UserTransaction
javax.ejb.EJBHomejava:comp/env/ejb
javax.jms.*java:comp/env/jms
@Resource(name="test")
void setDataSource(javax.sql.DataSource dataSource)
{
  _dataSource = dataSource;
}
javax.ejb.Resource
@Target({TYPE, METHOD, FIELD, PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Resource { String name() default ""; String resourceType() default ""; AuthenticationType authenticationType() CONTAINER; boolean shareable() default true; String jndiName() default ""; }

EJB
EJB
Amber
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.