Tuesday, May 02, 2006

EJB 3 - a basic study

EJB 3 is such a radical departure from EJB 2.

To begin with there is no need for the developer to define local or remote and localhome or remotehome interfaces.

All of the above is achieved by an intelliginet mix of default behaviour and annotations.

Here is an example


@Stateless
public class GreetingBean implements Greeting {
public String hello (String personName) {
return "Hello " + personName + "!";
}
}

public interface Greeting{
public String hello (String personName);
}

The above bean is a stateless bean with local accaess as the defualt. So no need to implement EJBLocalObject, EJBLocalHome, etc....

How do we make this a remote bean ?

@Stateless @Remote
public class GreetingBean implements Greeting {
public String hello (String personName) {
return "Hello " + personName + "!";
}
}

public interface Greeting{
public String hello (String personName);
}


How do we get access to this bean, if there is no Home Interface ?

Via "Dependency Injection" just like Spring.

The difference is, unlike Spring, EJB3 does not use an exteranl XML configuration file, what is used instead is, again an annotation !

@EJB Greeting greeting;
...
String helloString = greeting.hello("Krishna");


Webservices can be defined as annotations on session bean methods.

Also i hear that Entity bean persistence is much like an OR tool i.e. Hibernate et all.

0 Comments:

Post a Comment

<< Home