|
Page 1 of 2 I have been with EJBs for a fairly long time but I have been very much part of the "reluctant EJB developers" community. Give me an option to EJBs and in all probability I will take it. The primary reason was that I did not find EJBs worth the effort. The develop and deploy cycles were unacceptably long, the development seemed unnecessarily confusing, machines crawled once you had a EJB server + IDE running and ofcourse finding skilled EJB developers was a very difficult task.
So I wasn't very excited or optimistic about EJB3 when I first heard about it somewhere around JavaOne 2004. Every EJB3 session at JavaOne 04 was full and I remember wondering if all these people were there because they have used and found EJB fun or because they were hoping that finally with EJB3 they will understand what's happening and why their managers were forcing them to use EJBs.
I did do a few experiments with EJB3, but I was essentially waiting for tools to catch on. Today, all major J2EE vendors have at least a EJB3 preview release of their server and IDE. So I think it's time to learn EJB3.
NetBeans and JDeveloper are my preferred tools. I don't think NetBeans supports EJB3 as yet, so I decided to try out EJB3 using the recent preview release of JDeveloper 10g. I wrote a book on JDeveloper 10g in early 2004 titled Oracle JDeveloper 10g: Empowering J2EE Development, but that version of JDeveloper supported EJB2.1. JDeveloper's EJB 3.0 preview release is still called 10g, but I suppose Oracle will rename it to 11z or something like that when the final release is out.
Lets look at a simple stateless session EJB and try to understand what's new in EJB3. With the JDeveloper wizards, it took me less than aminute to create this app.
Listing 1: DateEJBBean Class
package example.model;
import javax.ejb.Stateless;
@Stateless(name="DateEJB")
public class DateEJBBean implements DateEJB, DateEJBLocal {
public DateEJBBean() {
}
public String displayDate() {
return ""+new java.util.Date();
}
}
In the DateEJBBean class in Listing 1, note the following:
- It's a Plain Old Java Object (POJO).
- It's not abstract.
- It does not force me to implement any interface/s apart from the ones that I have created.
- The Java annotation that states that this is a stateless session bean.
Listing 2: DateEJBLocal Interface
package example.model;
import javax.ejb.Local;
@Local
public interface DateEJBLocal {
public String displayDate();
}
Listing 3: DateEJB Remote Interface
package example.model;
import javax.ejb.Remote;
@Remote
public interface DateEJB {
public String displayDate();
}
<< Start < Previous 1 2 Next > End >> |