EJB 3.0 Demo

As Roman said, EJB 3.0 is a whole lot easier than in EJB 2.1. Forget about CMP mapping, deployment descriptors, or even having to create full-blown entity beans for your DB access. Just create a persistence unit then regular annotated POJO entity classes for each of your tables, and off you go. You can even use them in a regular J2SE project.

Lots of other things are much easier as well. My favorite is calling an EJB. First look at the gobbly-gook that is EJB lookup in EJB 2.1:

    private org.test.ProcessOrderLocal lookupProcessOrderBean() {
        try {
            javax.naming.Context c = new javax.naming.InitialContext();
            org.test.ProcessOrderLocalHome rv = (org.test.ProcessOrderLocalHome) c.lookup("java:comp/env/ejb/ProcessOrderBean");
            return rv.create();
        }
        catch(javax.naming.NamingException ne) {
            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
            throw new RuntimeException(ne);
        }
        catch(javax.ejb.CreateException ce) {
            java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
            throw new RuntimeException(ce);
        }
    }

Now the same thing in EJB 3.0:

    @EJB
    ProcessOrderLocal orderProcess;

Ahhhhhh.... I just feel sorry for the NetBeans engineers who did so much work to implement automatic generation of all that code.

Anyway, if you've got some time grab a cup of coffee and check out this flash tutorial, which shows you how to set up EJB 3.0 persistence in an EJB module, then access it using JSF in a web module. Again, it's a bit long (sorry) but it's worth it. I promise some shorter flash demos are coming!

Comments:

Post a Comment:
Comments are closed for this entry.
About

johnc

Search

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