More features in EJB.Lite

Asynchronous session bean



Non-persistent EJB Timer service







This also means these features can be used in embeddable EJB

container and there by improving testability of your

application.

This also means these features can be used in embeddable EJB container and there by improving testability of your application. Pruning - The following features were made Proposed Optional

in Java EE 6 and are now made optional.





in Java EE 6 and are now made optional. EJB 2.1 and earlier Entity Bean Component Contract for CMP

and BMP





and BMP

Client View of an EJB 2.1 and earlier Entity Bean



EJB QL: Query Language for CMP Query Methods



JAX-RPC-based Web Service Endpoints and Client View







The optional features are moved to a separate document and as

a result EJB specification is now split into Core and Optional

documents. This allows the specification to be more readable

and better organized.





The optional features are moved to a separate document and as a result EJB specification is now split into Core and Optional documents. This allows the specification to be more readable and better organized. Updates and Improvements





Transactional lifecycle callbacks in Stateful Session Beans,

only for CMT. In EJB 3.1, the transaction context for lifecyle

callback methods (@PostConstruct, @PreDestroy, @PostActivate,

@PrePassivate) are defined as shown.



















@PostConstruct

@PreDestroy





@PrePassivate





@PostActivate









Stateless





Unspecified





Unspecified

N/A





N/A









Stateful





Unspecified

Unspecified

Unspecified

Unspecified





Singleton





Bean's transaction



management type





Bean's transaction



management type

N/A





N/A















In EJB 3.2, stateful session bean lifecycle callback methods

can opt-in to be transactional. These methods are then

executed in a transaction context as shown.



















@PostConstruct

@PreDestroy





@PrePassivate





@PostActivate









Stateless





Unspecified





Unspecified

N/A





N/A









Stateful





Bean's transaction



management type

Bean's transaction



management type

Bean's transaction



management type

Bean's transaction



management type





Singleton





Bean's transaction



management type





Bean's transaction



management type

N/A





N/A















For example, the following stateful session bean require a new

transaction to be started for @PostConstruct and @PreDestroy

lifecycle callback methods.





@Stateful

public class HelloBean {

@PersistenceContext(type=PersistenceContextType.EXTENDED)

private EntityManager em; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

@PostConstruct

public void init() {

myEntity = em.find(...);

}



@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

@PostConstruct

public void destroy() {

em.flush();

}

}





Notice, by default the lifecycle callback methods are not

transactional for backwards compatibility. They need to be

explicitly opt-in to be made transactional.





only for CMT. In EJB 3.1, the transaction context for lifecyle callback methods (@PostConstruct, @PreDestroy, @PostActivate, @PrePassivate) are defined as shown. In EJB 3.2, stateful session bean lifecycle callback methods can opt-in to be transactional. These methods are then executed in a transaction context as shown. For example, the following stateful session bean require a new transaction to be started for @PostConstruct and @PreDestroy lifecycle callback methods. Notice, by default the lifecycle callback methods are not transactional for backwards compatibility. They need to be explicitly opt-in to be made transactional. Opt-out of passivation for stateful session bean - If your

stateful session bean needs to stick around or it has

non-serializable field then the bean can be opt-out of

passivation as shown.





@Stateful(passivationCapable=false)

public class HelloBean {

private NonSerializableType ref = ...



. . .



}



stateful session bean needs to stick around or it has non-serializable field then the bean can be opt-out of passivation as shown.

Simplified the rules to define all local/remote views of the

bean. For example, if the bean is defined as:

@Stateless

public class Bean implements Foo, Bar {

. . .

}

where Foo and Bar have no annotations of their own, then Foo

and Bar are exposed as local views of the bean. The bean may

be explicitly marked @Local as

@Local

@Stateless

public class Bean implements Foo, Bar {

. . .

}





then this is the same behavior as explained above, i.e. Foo

and Bar are local views.







If the bean is marked @Remote as:

@Remote

@Stateless

public class Bean implements Foo, Bar {

. . .

}

then Foo and Bar are remote views. If an interface is marked

@Local or @Remote then each interface need to be explicitly

marked explicitly to be exposed as a view. For example:



@Remote

public interface Foo { . . . }



@Stateless

public class Bean implements Foo, Bar {

. . .

}

only exposes one remote interface Foo.







Section 4.9.7 from the specification provide more details

about this feature.





bean. For example, if the bean is defined as: where Foo and Bar have no annotations of their own, then Foo and Bar are exposed as local views of the bean. The bean may be explicitly marked @Local as then this is the same behavior as explained above, i.e. Foo and Bar are local views. If the bean is marked @Remote as: then Foo and Bar are remote views. If an interface is marked @Local or @Remote then each interface need to be explicitly marked explicitly to be exposed as a view. For example: only exposes one remote interface Foo. Section 4.9.7 from the specification provide more details about this feature.

TimerService.getAllTimers is a newly added convenience API

that returns all timers in the same bean. This is only for

displaying the list of timers as the timer can only be

canceled by its owner.

that returns all timers in the same bean. This is only for displaying the list of timers as the timer can only be canceled by its owner.

Removed restriction to obtain the current class loader, and

allow to use java.io package. This is handy if you want to do

file access within your beans.

allow to use java.io package. This is handy if you want to do file access within your beans.

JMS 2.0 alignment - A standard list of activation-config

properties is now defined





properties is now defined

destinationLookup





connectionFactoryLookup





clientId





subscriptionName





shareSubscriptions

Tons of other clarifications through out the spec. Appendix

A provide a comprehensive list of changes since EJB 3.1.

A provide a comprehensive list of changes since EJB 3.1.

ThreadContext in Singleton is guaranteed to be thread-safe.



Embeddable container implement Autocloseable.

EJB 3.1 added a whole ton of features for simplicity and ease-of-usesuch as @Singleton, @Asynchronous, @Schedule, Portable JNDI name,EJBContainer.createEJBContainer, EJB 3.1 Lite, and many others. Aspart of Java EE 7, EJB 3.2 ( href="http://jcp.org/en/jsr/detail?id=345">JSR 345) is makingprogress and this blog will provide highlights from the work done sofar. This release has been particularly kept small but includeseveral minor improvements and tweaks for usability.

A complete replay of href="https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4654">Enterprise

JavaBeans Today and Tomorrow from JavaOne 2012 can be href="https://oracleus.activeevents.com/connect/sessionDetail.ww?SESSION_ID=4654">seen

here (click on CON4654_mp4_4654_001 in Media).



The specification is still evolving so the actual property or

method names or their actual behavior may be different from the

currently proposed ones.

Are there any improvements that you'd like to see in EJB 3.2 ?

The EJB 3.2 Expert Group would love to href="http://java.net/projects/ejb-spec/lists/users/archive">hear

your feedback. An href="http://download.oracle.com/otndocs/jcp/ejb-3_2-edr-spec/index.html">Early

Draft of the specification is available. The latest version

of the specification can always be downloaded href="http://java.net/projects/ejb-spec/downloads">from here.



These features will start showing up in href="http://dlc.sun.com.edgesuite.net/glassfish/4.0/promoted/">GlassFish

4 Promoted Builds soon.

