File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes New features for entity beans in EJB3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "New features for entity beans in EJB3" Watch "New features for entity beans in EJB3" New topic

New features for entity beans in EJB3

vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
Hi Raghu and Jonathan,
can you elucidate on the 'interceptors' in the new EJB3 and does your book throw light on this new feature?

Also I have read that the new EJB3 has changed the way enterprise beans are called and accessed by replacing the service locator pattern that utilizes JNDI with something called 'Dependency Injection Pattern' (Courtesy: Java World). Can you explain what this means please.
[ October 24, 2006: Message edited by: vishwanath nadimpally ]
Jon Wetherbee
Ranch Hand

Joined: Oct 05, 2006
Posts: 33
Hi Vishwanath-
Sure. Interceptors are an AOP (Aspect-Oriented Programming) construct that allow you to perform additional work whenever a particular method is called. To take a classic example, you might want to audit one or more business methods on your session bean to record whenever they are called. Instead of modifying the business methods themselves, you declaratively assign one or more interceptor methods to be "wrap" the call to the business method. Interceptor methods are annotated with the annotation, and they may be defined on the class to which they apply, or on an external class. In the latter case, the session or message driven bean specifies one or more interceptor classes that will handle calls to the bean methods. When more than one interceptor method is specified for a particular method context, they are nested, following well-defined rules of precedence. The first one is called, and it in turn calls the next one, and so on, until finally the business method on the bean itself is invoked. In addition, an interceptor method may at any point decide to throw an exception, or cancel the method call.

The key to interceptors is that neither the business method being called, nor the client that calls it, need to be modified in any way to know that the call is being interposed by interceptor methods. Interceptors can be specified through annotations or in XML. Interceptors can apply to multiple methods, possibly across multiple beans, you can turn interceptors on or off, and you can selectively choose which business methods on your bean to intercept.

JPA entities do not support interceptors per se, but instead support a well specified set of entity lifecycle event entrypoints, called entity listeners. These callback methods allow you to perform additional work during the following entity lifecycle events:


I agree. Here's the link:
subject: New features for entity beans in EJB3
It's not a secret anymore!