EJB 3.1 in GlassFish V3 TP2

In this blog, I will describe some of the EJB 3.1 features that are available in GlassFish V3.

For a full list of what is planned in EJB3.1 please refer to Ken's blog

Note: Before, you run any of the EJB 3.1 applications ensure that you follow the steps outlined in Installing EJB container in GlassFish V3

What EJB features are available in GlassFish V3 TP2

Only Stateless Session beans with local interfaces are supported. Stateful, Message driven and EJB 2.x entity beans are not supported. Remote interfaces and Remote business interfaces for any of the bean type are not supported yet. Timer Service is supported, but a little bit of configuration is needed to enable it. We will be blogging about how to enable TimerService in GlassFish V3 shortly.

Support for other types of beans will be available soon.

Note: TP2 gives you an early look at GlassFish v3. It is not a full, feature-complete application server and is not suitable for production deployments. It is suitable for experimentation and exploration. Experiment, take a look at the new approach being taken in GlassFish v3, and then let us know what you think

Using GlassFish V3 server

To run the sample application provided, follow the steps mentioned in How to run the hello.war

Quick start guide provides more details on how to use the GlassFish V3 server.

Optional Local Business Interfaces

Recall that even though EJB 3.1 simplified the EJB development by introducing the business interfaces, the bean developer must still write at least one interface. For most of the applications this is again an overhead. In EJB 3.1 an EJB need not implement any interface as long as it contains one of the component defining annotations (or the XML equivalent). So a simple EJB 3.1 HelloBean looks like this:

@Stateless
public class HelloBean {
public String sayHello() {
return "Hello, World!!";
}
}

Note: The client still has to perform a JNDI lookup or inject a reference of the bean. More specifically, it cannot use the new operator to construct the bean.

So a Servlet that use the HelloBean will be coded like the following: public class HelloServlet {
@EJB private HelloBean hello;
....
hello.sayHello();
....
}

Simplified packaging

JavaEE 5 greatly improved the ease of use by providing a bunch of annotations that that obviated the need for XMLs. However, it still required that Servlets/JSPs be packaged in a .war file and EJBs be packaged (in possibly multiple) .jar files. These files must further be packaged inside a .ear file. For simple web applications that wanted to use EJBs, the above packaging restrictions was a bit of an overkill

Another cool feature that is introduced in EJB 3.1 is the simplification of packaging requirements of EJBs. Now, EJB classes can be packaged inside the .war file itself!! The classes must reside under WEB-INF/classes.

Because of the above two features, the structure of our hello.war looks like this.

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
WEB-INF/classes/com/sun/
WEB-INF/classes/com/sun/v3/
WEB-INF/classes/com/sun/v3/demo/
WEB-INF/classes/com/sun/v3/demo/HelloEJB.class
WEB-INF/classes/com/sun/v3/demo/HelloServlet.class
WEB-INF/web.xml
index.jsp

How to run hello.war

Download the attachments provided. HelloEJB31.war contains the application that can be deployed. HelloEJB31.zip contains the sources.

  1. Start the server by running: <install_dir>/asadmin start-domain
  2. Deploy the application by running: <install_dir>/asadmin deploy hello.war
  3. Open a browser and go to: http://localhost:8080/HelloEJB31/HelloServlet

Comments:

See http://blogs.sun.com/marina/entry/enabling_ejb_timers_in_glassfish for information on how to enable TimerService in GlassFish V3

Posted by Marina on May 06, 2008 at 03:06 PM PDT #

Hi Mahesh, great article, let me ask you, did you try to test an asynchronous method ?
Regards

Wagner

Posted by Wagner Santos on May 22, 2008 at 05:10 PM PDT #

[Trackback] The EJB 3.1 specification says: An enterprise bean class with a component-defining annotation defines an enterprise bean component when packaged within the WEB-INF/classes directory or in a .jar file within WEB-INF/lib. In simple English it means, an ...

Posted by Arun Gupta's Blog on January 19, 2009 at 08:15 AM PST #

Hi, when i try to deploy HelloEJB31.war attached, it reports an error like:
message: Exception while deploying the app : java.lang.RuntimeException: Invalid ejb jar [HelloEJB31]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message driven bean.
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven), please check server.log to see whether the annotations were processed properly.

Posted by Amy on March 05, 2009 at 12:48 PM PST #

Hello All,

I am looking for a EJB3 and GF based distributed sample application. I would appreciate if you anything available at your side.

Thanks Much !!!
................
Dramil Dodeja
http://dramildodeja.webnode.com/
https://sites.google.com/site/dramildodejajavablog/

Posted by dramil dodeja on January 16, 2011 at 03:44 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Mahesh Kannan

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today