Appendix C. Annotations reference

 

In this appendix, we list all the EJB 3 annotations we talked about throughout the book. This appendix is designed to be a quick reference you can use while developing your enterprise application. See the individual chapters for the full details of each annotation.

The annotations are organized by topic, roughly following the same sequence as the chapters.

C.1. Session and message-driven beans

The following are all the annotations that are used in session and message-driven beans.

C.1.1. Session beans

These annotations are used for stateless and stateful session beans.

javax.ejb.Stateless

Marks a POJO as a stateless session bean.

javax.ejb.Stateful

Marks a POJO as a stateful session bean.

javax.ejb.Remove

Denotes a business method as the remove method of a stateful session bean.

@Target(METHOD) @Retention(RUNTIME)
public @interface Remove {
boolean retainIfException() default false;
}

The @Remove annotation has one element: retainIfException. If it is set to true and an exception is thrown from designated method, the bean will not be removed.

javax.ejb.Remote

Marks a POJI as a session bean remote business interface.

@Target(TYPE) @Retention(RUNTIME)
public @interface Remote {
Class[] value() default {};
}

The @Remote annotation can be applied on both on a bean class or on a business interface. The class element is used to specify the name of the interface when @Remote is applied on the bean class.

javax.ejb.Local

C.2. Java Persistence API annotations