Whats new in JEE 6 ( except CDI )
We were lucky to visit both days of Sun Tech Days 2010 event, listened to news regarding JAVA related technologies, had a chance to talk to some Java evangelists and of course participated in the freebies frenzy that followed the lectures on day one. Overall impresstion is that although now owned by Oracle, JAVA and related technologies will be going forward and none will be left behind. Sun tries to keep up to and even stay ahead of competition in a wide variety of fields. I`d like to focus this post on whats new in JEE 6.
JEE6 is available with set of profiles, outlining subsets of functionality for ease of use. Most of the new features in JEE 6 Web Profile are presented below, except for CDI. Web profile for JEE6 is supported by Glassfish v.3 ( released December 2009 ) and is of production quality - Sun recommends it for using in real life production environments. All the topics below have samples and tutorials with code to explain the new features, available here: https://svn.kenai.com/svn/beginningee6~src
Managed beans 1.0
Managed beans are basically "Container-managed POJOs" that support some basic functionality via annotations, such as: Injection (@Resource...); Life-cycle management (@PostConstruct,@PreDestroy); Interceptor (@Interceptors, @AroundInvoke);
There are few specifics and requirements regarding Managed Beans:
- public default constructor for basic implementations
- annotated with @javax.annotation.ManagedBean
- not implementing serializable, not final, abstract or non-static inner class.
- method invocations on a Managed Bean execute in the same thread as the caller
- Managed beans are optionally named by strings passed to the MangedBean annotation
- container must make beans available using JNDI portalbe names specific to application or module namespaces
- Better Map support - Basic, Embeddable, Entity as keys. Annotations: @OneToMany(mappedBy="..."); @MapKeyColumn, etc
- Derived Identifiers for OneToOne and ManyToOne relationships
- Nested embedding - Embeddable types having Embeddable members
- New collection mappings - Support for collections of Basic or Embeddable types.
- Ordered List mappings - Support for maintaining an index column in any collection relationship using a List.
- Pessimistic Locking
- Cache APIs - @Cacheable
- Criteria API accessible via CriteriaBuilder class, allowing use of dynamic queries via class names, checked at compile time.
- Richer JPQL - more JOINs, etc
- All connection options in persistence.xml - standard configuration
Main changes since Servlets 2.5 specification were targeting Ease of Development, Pluggability, new Async. operations support.
- Lots of new annotations making web.xml totally optional.
- Listeners specs and such can now be put into web-fragments ( parts of web.xml ) and shipped with .jar = easier framework development
- Listener ordering
- New async support through @WebServlet(asyncSupported=true) for long running requests.
- Per servlet security via @ServletSecurity
- Elimination of requirement for EJB component interfaces for session beans - interfaces are now optional
- @Asynchronous support, methods returning void or Future
- TimerService, using @Schedule (dayofweek="..", ... ) annotations
- @Singleton support, implements singleton pattern in application / JVM, works with @PostContruct & @PreDestroy
- API for programmatic container management
- Ability to run in Java SE environment - tests run times greately improved
- Web profile for JEE 6 supports EJB 3.1 Lite
- Too much more to cover here... check JSR 318
- Take two at usable MVC framework
- Adopts Facelets as VDL
- web.xml, faces-navigation.xml are now optional
- Introduces JSF Composite component for easy component development
- AJAX support inspired by Richfaces, Icefaces, etc... use of
to ajaxify exisitng pages.
- Numerous minor improvements: Validation moved to BeanValidation 1.0, easier resource and error management, Groovy support
- Also have a @javax.faces.beans.ManagedBean annotation, not to confuse with one specified by Managed Beans 1.0
Bean Validation 1.0
Main objective of Bean Validation 1.0 is to allow developers to follow "Constrain Once, Validate Everywhere" approach, allowing to specify validation rules once and have data validation on every stage of information processing: persitence layer, controller and view.
- Enables declarative validation through the application via @NotNull, @Size, @Valid annotations. @Valid instructs recursive validation for specified fields.
- Integrated with JPA 2.0 and JSF 2.0
- Easy development of validator classes applicatble in standard way
- Partial validation
- Internationalization support
- Validation Ordering
- POJOs exposed as webservices via annotaions such as @Consumes, @Produces, @Path, etc
- Mapping HTTP verbs to certain API classes and annotations
- Integrates with JEE 6 EJBs
Also managed to take couple of snapshots during the conference, below are Simon Ritter and some others..
And finally a line of dukes ready to take over the world!