Friday, December 01, 2006

@IndictThreads Java Conference

I've been traveling in India for about 10 days now. Now I'm in Poona attending the IndicThreads Java conference. Great work by Harshad Oak and his crew in arranging such a Java conference in India. I spoke yesterday and my session was tittled EJB 3 in Action and it was a house full. I will have a Q & A session along with Gavin King on EJB3 / JPA later today.

Tuesday, November 07, 2006

Spring/EJB 3 HowTos/Code Examples

I built couple of howtos for using Spring 2.0 with EJB 3/JPA and these have been referenced from Spring's home page.

How To: Using EJB 3.0 Session Beans with Spring Beans : Zip with Code examples In OTN

How To Use EJB 3.0 and Java Persistence API with Spring : Zip with Code examples In OTN

Please note that this works with Oracle Application Server 10g

These samples also work with Glassfish by tweaking the packaging a little bit. You have to just make sure that you modify the packaging to include Commons Logging jars required by Spring. If you want the build script for Glassfish please drop me an email and I will send that to you.

Thursday, November 02, 2006

My Book @

Finally my book EJB 3 In Action is available at for pre-order. The book has already been available for purchase under Manning's MEAP program that provides ability to read pre-production version of the book today!

Pre-order at Amazon

Pre-order and MEAP at publisher's website

Wednesday, November 01, 2006

EJB 3 Extensions in Oracle Application Server 10g

Oracle has built some extensions to its EJB 3 implementation in Oracle Application Server to simplify developers' life. In this blog I will uncover these extensions.

Vendor Specific Annotations

We have added three proprietary annotations @StatelessDeployment, @StatefulDeployment and @MessageDrivenDeployment that you can use to specify Oracle specific configurations for your bean. This frees you from having to deal with vendor specific descriptor. For example, you can use the @StatelessDeployment annotation to specify pooling information for an EJB as follows:

import oracle.j2ee.ejb.StatelessDeployment;

@StatelessDeployment(minInstances = 100, maxInstances = 500)
public class HelloBean implements Hello {


Additionally we have provided annotations to be used with EJB 3 web services (that use web services metadata annotations) : @Deployment, @Schema, @WSIFEJBBinding, etc. The @Deployment annotation is most important annotation of these and can be used to specify portName, contextPath or expose the web service as a REST web service.

For example:

@Deployment(contextPath="ejb30", uriPath="ejb30-simple", portName="MyWebService")
@Statelesspublic class HelloBean{


You can refer to the Oracle Annotations Java Doc for details about these annotations.

Simplification to Use JPA inside container

We have added several small knobs here and there to simplify use of JPA inside container.

persistence.xml is optional in EJB Modules

JPA requires persistence.xml for configuring a persistence unit. This is really a headache for developers when using entities in an EJB module and has only one persistence unit. Oracle Application Server makes it optional and will search for entities in the ejb-jar and configure a default persistence unit for you. The data-source will be defaulted to the default data source configured for the application or server. This will also help customers using EJB 3 in OracleAS to migrate to OracleAS easily.

Using @Resource annotationInjecting container-managed EntityManager

Many developers have asked why can’t they use @Resource annotation to inject a container managed EntityManager? It seems really odd that you can inject other resources such as DataSource but not EntityManager. The real answer is EntityManager is not a resource and you may have more than one persistence unit. If you have only one persistence unit in your application OracleAS has extension to support injection of EntityManager using @Resource as follows:
@Resource EntityManager em;

This also helps customer to migrate their applications to OracleAS from earlier release.

persistence.xml in WEB-INF

If you have used entities in the web module then you know that Java EE 5 requires packaging of persistence.xml in the WEB-INF/classes/META-INF directory. It is really confusing for developers because all descriptors for web module are placed in WEB-INF directory. Why not persistence.xml you may ask? There is a real reason (and there was hot discussion in the EJB3 expert group) for this that I will discuss in a future blog. However it is worth mentioning here that OracleAS makes it simple and allow packaging of persistence.xml in WEB-INF/ directory and if found it will be considered to similar to packaging it in WEB-INF/classes/META-INF directory.

Hope these extensions make your life easier. If you have an idea for a feature that you would like to see in OracleAS do not hesitate to send that to me.

Thursday, October 26, 2006

Is BEA far ahead in Java EE 5 game?

It was interesting to read this article in Dr Dobb's Java portal (and InfoQ' s thread ) that noted that BEA is ahead of others in the Java EE 5 game. In my personal opinion (note that this blog is my personal opinion and nothing to do with my employer's), these are really biased articles and reflects the mindset of the writer "BEA is always ahead!"

As per the article EJB 3/JPA covers significant portions of Java EE 5 and hence the reality shows otherwise. Oracle and JBoss had EJB 3 previews for years (yes years, we released our first EJB 3 preview in early March 2005, See my announcement) and both JBoss and Oracle have production release of EJB 3/JPA in their application server. Look for complete EJB 3/ JPA support in Oracle Application Server 10g whereas BEA just has tech preview of a subset of EJB 3 specification. They have support for Java Persistence API in Kodo but the article in DDJ also acknowledges Kodo is not yet integrated with the WebLogic and hence you cannot use its full power. However Oracle’s JPA implementation TopLink Essentials is totally integrated with Oracle's Java EE container (OC4J) and is also shipped with Glassfish, TmaxSoft and popular Spring 2.0!.

Beside full implementation of EJB 3 and JPA, Oracle has also support for Web services metadata, annotations support in the Servlet (2.5) and application client container in Oracle Application Server ( Above all these features work in a truly integrated fashion that customers can use in production today. You cannot use JSR-181 annotations with an EJB 3 session bean in a production environment with WebLogic but can do that today with OracleAS !

Try running a complicated application such as Java Adventure Builder that uses EJB 3 /JPA / Web services metadata in the WebLogic Tech Preview. If you can’t do these things then what made the author to assume that BEA is ahead of JBoss and Oracle in the Java EE 5 game.

It truly frustrates me when seeing such biased articles because many gullible readers treat such articles as bible.

Many Oracle customers have started deploying EJB 3.0/JPA applications in production. Can you do that with BEA? If not then how can you say that they are ahead in the game!

EJB 3 In Action: What's what in EJB 3

Manning has made available 9 chapters of EJB 3 In Action as part of MEAP Release. Draft version of chapter 1 “What’s what in EJB 3" is available for free. Take a look at this at

You will probably like the beginning story of an Indian boy named Sadhu and it's comparison with EJB’s incarnations. You can access the chapter at

Wednesday, October 25, 2006

Java annotations support in the web container

Servlet 2.5 (a part of Java EE 5) provides support for Java metadata annotations. You can use annotations for callback methods, security, injection of resources, EJB and web service reference, EntityManager, etc.

You can also package a persistence module (EJB3 JPA entities) as a part of a WAR module.

Injection of Resources

You can use the @Resource annotation to inject resource references such as Data Source e.g. you can inject a Data Source as follows:

private DataSource dataSource;

CallBack Methods

You can use @PostConstruct and @PreDestroy annotations with any arbitrary method to behave like init() and destroy() methods respectively. For example you can have a method named openConnection that opens a connection as follows:

public void openConnection() {
try {
connection = dataSource.getConnection();
} catch (SQLException sqle) {

Things to Remember

Note that annotations are supported only with managed classes such as servlet, filters, listeners, etc. You cannot use annotations with regular POJOs.

You have to make sure that you have set version=”2.5” in the web.xml for the web-app tag as follows: ...


If you have set that to a lower version or not set then container will not search for annotations and you will probably get a NullPointerException at run time when trying to use a field assuming it’s value to populated using injection.

OC4J supports all Servlet 2.5 annotations that includes @EJB, @Resource, @Resources, @PostConstruct, @PreDestroy, @PersistenceUnit(s), @PersistenceContext(s), @WebServiceRef, @DeclaresRoles, @RunAs.

It also allows packaging of EJB 3/JPA entities in the web module.

Missing annotations ..!

I think one think that is missing is that there are annotations to specify a type of an object similar to @Stateless annotation in EJB 3.0.

For example, you CANNOT mark a POJO to be a servlet as follows:
public class MyServlet
{ …

I would like to see annotations such as @Servlet or @Filter in future version of Servlet specification.

More Info

You can find more about Servlet annotations in Servlet 2.5 spec or OC4J documentation.

Friday, October 20, 2006

Oracle Application Server Goes Production

Oracle announced production release of Oracle Application Server10g This release of OC4J implements significant features of Java EE 5.0 that includes full implementation EJB 3.0, JPA 1.0, Common Metadata annotations 1.0, Servlet 2.5 annotations, annotations support in the Application Client Container support and web services metadata.

You can download from OC4J home page at

Oracle Application Server Goes Production

Oracle announced production release of Oracle Application Server10g This release of OC4J implements significant features of Java EE 5.0 that includes full implementation EJB 3.0, JPA 1.0, Common Metadata annotations 1.0, Servlet 2.5 annotations, annotations support in the Application Client Container support and web services metadata.

You can download from OC4J home page at

Friday, October 13, 2006

Early Access Edition of EJB 3 In Action

I participated in several beta and early access testing of products, reviewed books but never participated in an Early Access Program for a book. And certainly Manning Early Access Program sounds interesting.

An early release version of my book EJB 3 Action is now available at

It's a little better form of pre-ordering from Amazon or a publisher web site. You immediately get access to the source or final pre-production version of the book online and Manning Publications will ship you a book as soon as book is published. In the mean time you are the beta testers of the book (:

I will appreciate you participate in this program, pre-order a copy and help find any errors in the book (:

Wednesday, September 20, 2006

JavaZone @Oslo!

My trip to Oslo was very nice. The weather was pretty good there. It was my first talk at JavaZone. It is really a nice Java conference. It's certainly better, bigger than the conferences like TheServerSide symposium. About 1400 people attended.

All familiar conference presenters Rod Johnson, Joshua Bloch, Floyd, Patrick Linskey, etc were presenting there.

One thing that I liked about the conference that there it was free from keynote. My presentation Migration to EJB3 was houseful! You can download my presentation from JavaZone website.

Thursday, September 07, 2006

My upcoming talks at JavaZone and OracleDevelop

I’ll be presenting in JavaZone, Norway next week. Hope to see you if you are attending the conference. I will deliver a presentation on Oracle Develop conference held Oct 23-25. . This conference is primarily for developers using Oracle platform and there will be many talks for developers. There are many great speakers including Rod Johnson who will present in the Oracle Develop conference.

Hope to see you in one of these conferences!

Thursday, August 24, 2006

Using EJB 3.0 Message Driven Bean with JCA-Resource Adapters

MDB was the only bean type that did not suffer obesity problems with EJB 2.x. It was simple to develop and use and it was liked by most developers.

For many developers the verbose XML descriptor was still a sour-point. EJB 3.0 further simplified message driven bean by removing the requirement to use descriptors and you can use annotations to specify the activation config properties.

An Example MDB with EJB 3.0 Annotations

A simple MDB will look like as follows:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "ConnectionFactoryJndiName", propertyValue = "jms/TopicConnectionfactory"),
@ActivationConfigProperty(propertyName = "DestinationName", propertyValue = "jms/demoTopic"),
@ActivationConfigProperty(propertyName = "DestinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "RECIPIENT = 'MDB'")

public class MessageLogger implements MessageListener{..}

This problem with MDB is that it works will the default JMS provider of the container i.e . in-memory JMS provider of OracleAS.

Using MDB with a JCA-compliant Resource Adapter

There are many instances probably you want to use a messaging provider (JMS or non-JMS) plugged-in using a JCA-compliant connector or resource adapter. Let us assume that OracleAS JMS wit the global connector (named OracleASjms) packaged with Oracle AS. Unfortunately EJB or JCA does not standardize configurations for using a resource adapter and you have to depend upon a proprietary feature such as vendor specific annotation or activation config property to designate the resource adapter to be used with your MDB. Oracle provides a vendor specific annotation (@oracle.j2ee.ejb.MessageDrivenDeployment) to specify Oracle specific configuration properties and you need to use resourceAdapter element to specify the resource adapter that you intend to use. For example you can modify the above MDB as follows to use the OracleASjms global connector to use the In-memory JMS as follows:

@oracle.j2ee.ejb.MessageDrivenDeployment(resourceAdapter="OracleASjms")@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "ConnectionFactoryJndiName", propertyValue = "OracleASjms/MyTCF"),
@ActivationConfigProperty(propertyName = "DestinationName", propertyValue = "jms/demoTopic"),
@ActivationConfigProperty(propertyName = "DestinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "RECIPIENT = 'MDB'")

public class MessageLogger implements MessageListener {.}

Note that we have modified the ConnectionFactoryJndiName to use a pre-configured connection factory OracleASjms/MyTCF.

Using a non-JMS Connector

Let us assume that you want to use your own non-JMS resource adapter let us say thirdra then your EJB 3.0 MDB will look as follows:

import oracle.j2ee.ejb.MessageDrivenDeployment;
import thirdra.common.ThirdListener;

public class MessageLogger

Isn’t is simpler than EJB 2.x where you had to handle at least two XML descriptors? If you want to use mix-n-match with descriptor (ejb-jar.xml) make sure that version is set to "3.0" in your ejb-jar element otherwise annotations will not be parsed and container will treat it as an EJB 2.1 descriptor.

However I strongly feel that specifying a resource adapter should be standardized by the future release of specification.

Thursday, August 17, 2006

Top 5 features you would care about in OC4J!

OC4J Developer Preview was released couple of days back. OC4J was released in January that had a truckload of features. A question that might comes to your mind: Is OC4J a patch release? From Java developer’s perspective OC4J may not be feature-rich like OC4J However it has a lot of features that you might care about.

1. It now has complete implementation of EJB 3.0/JPA final specifications. It means you will see several changes in the EJB container, that includes:
  • EJB 3.0 Persistence now fully aligns with the spec.
  • Lifecycle listeners and Interceptors are aligned with the spec.
  • XML descriptors support is aligned with the spec.

See the updated demos at EJB 3.0 Resource Center.

2. We have added Oracle specific annotations for easier configurations. If you hate descriptors you have an option to make EJB configurations without having to use orion-ejb-jar.xml. Additionally we have added many proprietary enhancements to make usage of EJB 3.0 simpler. We have made persistence.xml optional in an ejb-jar module for packaging entities and use @Resource to inject the EntityManager for the default persistence unit. I will blog about these later.

3. Dependency injection is supported in the application client container and web container. You can use JSR 250 annotations in the web container. and also you can package entities in the web container. Also we have added the library module support in the application level. You can add a lib directory in the EAR level and any jars put in the lib directory will available to all modules in the EAR.

4. We implemented dynamic byte code generation for EJB wrappers and that greatly improves deployment of EJB applications. Most EJB applications should see between 30-70% improvement in deployment from OC4J 10.1.3 in identical configurations.

5. We have added a lot of new ANT tasks to make your life easier e.g. creation of data sources, JMS objects, shared libraries, etc.

Beside that we have a lot of bug fixes. So please try out and give us your feedback.

Here is link again :

Tuesday, August 15, 2006

Oracle SOA Suite - Complete EJB3 and JPA Support

Yesterday Oracle released Oracle Application Server 10g ( Developer Preview. The goal for this release to simplify development and deployment of service-oriented applications and hence it is termed as SOA Release. The SOA suite provides complete set of service infrastructure components such as Enterprise Service Bus, BPEL, BAM and Web Services Manager for creating, deploying and managing services, all available in a single install.

If you are an enterprise java developer and do not care about SOA, OracleAS has something for you too. O It has complete support for EJB 3 and Java Persistence API and has annotations support in the Servlet container. OC4J includes TopLink Essentials as the EJB3 JPA Provider.

You can download JDeveloper and OC4J standalone and to build and deploy EJB3/JPA applications.

See EJB3 Resources for updated howtos, samples, articles, etc.

Monday, August 14, 2006

Developing a Spring-enabled Session bean

In one of my blog entries last month I showed how you could access an EJB 3.0 Session bean from Spring 2.0 beans. One of the readers wanted to know whether it is possible to use Spring with EJB 3.0. Interestingly Spring documentation does not say anything about EJB 3.0 beans support with Spring 2.0. I managed to get this to working Spring 2.0 RC2 and in this article; I will show how you can develop a Spring-enabled EJB 3.0 Session bean.

Spring-enabled EJB 3.0 Session bean.

Spring provides abstract classes such as and that you can use to build a Spring-enabled EJB 3.0 session bean. You have to extend the abstract session bean class and implement the onEjbcreate method where you can retrieve the required bean instance from the bean factory as in the following example:

public class EmployeeFacadeBean extends
AbstractStatelessSessionBean implements EmployeeFacade

EmployeeServiceBean empService;

protected void onEjbCreate()

empService = (EmployeeServiceBean)


public Employee addEmployee(String empName, double sal) {

return empService.addEmployee(empName,sal);


Note that our stateless session bean EmployeeFacadeBean extends AbstractStatelessSessionBean. Note that we have implemented the onEjbCreate method that retrieves instance of EmployeeServiceBean from the bean factory.

The EJB deployment descriptor

The application context is passed to the Session Bean by using an environment variable named ejb/BeanFactoryPath in the deployment descriptor (ejb-jar.xml) as follows:


Note that the howto-service.xml contains the bean factory configuration that we see next. The howto-service.xml is packaged in the ejb-jar module.

Wiring all together with Spring configuration

The howto-service.xml contains the Spring configuration.
EmployeeServiceBean uses EmployeeDAO that is injected using setter injection:


<bean id="empService" class="oracle.ejb30.EmployeeServiceBean">
<property name="employeeDAO">
<ref bean="employeeDAO">

Remember that the Spring enabled EJB 3.0 Session bean (EmployeeFacadeBean) invokes the EmployeeService bean from the bean factory

empService = (EmployeeServiceBean) getBeanFactory().getBean("empService");

Client Code:

Let us assume that a servlet accesses the Spring-enabled EJB as follows:

public class InsertServlet extends HttpServlet
private EmployeeFacade ef;


public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String name = "";
Double sal = new Double(0);

name = request.getParameter("empName");
sal = Double.valueOf(request.getParameter("Sal"));
Employee emp = ef.addEmployee(name,sal);
System.out.println("Successfully persisted an employee");
this.getServletContext().getRequestDispatcher("/jsp/success.jsp").forward(request, response);
catch(Exception e)


If you look at the above code you will see that the Servlet uses dependency injection using @EJB (Java EE) to get an instance of Spring-enabled EJB and then invoke its method.


After you package your application, you should be able to deploy and run the application that uses a Spring-enabled EJB 3.0 session bean. Note that I tested this with Oracle Application Server 10g and I expect it to work in other application servers that support EJB 3.0. In a follow-up blog, I will discuss how you can use Spring’s JpaTemplate with a container-managed EntityManager within a Java EE container.

Thursday, August 10, 2006

Same house and same job but a new blog!

Changes are part of our life! New car, new computer or new kids are always fun! They bring excitement to life. But sometime we have emotional attachment to old things, old houses, etc. And I had the same with my old blog-site ( and was resisting for a change. I used Radio UserLand for more than two and half years and although I never liked it user interface, ability to restore old blogs I was still emotionally attached that being my first blog site.

Finally I decided to desert it. Some shortcomings in Radio Userland literally drove me crazy and I was not able to blog almost for a month after my laptop crashed! I had to pay Price for Carelessness.

My old blog site was getting fairly good number of hits averaging around 300 hits a day with some days around 2000-2500 hits. It has a good number of popular and controversial blogs that were linked from many web sites including, JavaWorld,, etc and hence leaving the old blog home was not an easy decision. I will try to restore some of my popular old blogs in the new blog site so that these are not lost when my license expires with Radio UserLand and they trash these pages. So stay tuned when I return to normal bogging schedule!