Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 11/18/2004; 5:20:24 PM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, May 07, 2004

Evolution from Hibernate to EJB 3.0

 

Gavin King was as articulate as Hibernate in his presentation “EJB to Hibernate to EJB 3.0” and provided a good summary of the latest state of EJB and Hibernate and how the persistence model is evolving in the EJB 3.0.

 

In he was very clear of the limitations of CMP entity beans and what motivated him to develop Hibernate. He was pleased that Hibernate was very well received among the developers he recognized the fact that without standardizing the technology it does not earn the adoption in the enterprise.  With this it is very clear that JBoss/Hibernate has thrown their support to EJB 3.0.

 

He provided an insight to the persistence model but not in any greater detail that what Linda DeMichiel provided in her talk yesterday. Take a look at my earlier blog entry for details about EJB 3.0 at http://radio.weblogs.com/0135826/2004/05/07.html.

 

To summarize here is the CMP entity beans will look like:

 

 

  • Ease of development
  • POJOs Programming Model
  • Will support Inheritance/Polymorphism
  • Will have an entity manager API similar to Hibernate Sessions
  • JSR-175 annotations to avoid XML mappings and deployment descriptors
  • No standardized O-R mapping
  • Enhanced EJB-QL to add additional SQL features
  • Support Pagination, Named queries, dynamic queries
  • Support native SQL queries
  • He clarified that Hibernate will continue to exist beyond EJB 3.0 for experimentation.


    12:18:21 PM    comment []

    EJB 3.0 – Looks simply great!

     

    It was a full house as I had predicted earlier when Linda DeMichiel, the spec lead of the EJB 3.0 expert committee presented on the plans for EJB 3.0 in the TheServerSide symposium today. So all those guys love and hate EJBs were present in the session. The main goals of EJB 3.0 are to simplify EJB for developers and make this attractive for all J2EE developers. It appears that the expert committee has kept their ears open for a while and has been trying to address all concerns around EJBs and mainly the container managed persistence. Let us see what are the plans in EJB 3.0.

     

    Simple for Development 

    The current EJB is very heavy weight and confusing for developers. The developers have to create several interfaces and to write a cryptic deployment descriptor.

     

    Following are proposals to make EJB simpler than the current model:

     

    • Remove need for building the EJB interfaces and generating the deployment descriptors and provide ability to developers to generate these by specifying annotations as in JSR 175. This will free developers from:
      • Creating deployment descriptors
      • Build component Interfaces
    • Simplify EJBs to resemble POJOs or Java Beans.
    • Elimination of requirement to have component interfaces for EJBs.
    • The entity beans do not require any component interfaces.
    • The session beans will use a Plain Old Java Interface
    • Elimination of requirement to implement unnecessary callback methods.

     

     

    So instead of two interfaces and a bean implementation class for a Session bean and defining a deployment descriptor for the Session Bean the developer has to define the EJB as follows. The following example shows the code for a HelloWorld bean:

     

    @Session public class HelloWorldBean {

    public void sayHello (String s) {

    System.out.println(“Hello:”+s);

    }

    }

     

    Apparently this looks much simpler than earlier and will appeal developers to use EJBs in their business logic layer.

     

    Hide complexity of JNDI

     

    Every EJB developer has gone through the pain of JNDI at least once in his/her lifetime. EJB 3.0 courageously target to hide the complexity of JNDI by providing several options such as declarative expression for dependencies, container injection of resources and simple programmatic lookup mechanisms.

     

    Here is a simple example how the JNDI lookup is being simplified. This sample illustrates a stateless session bean accessing a DataSource object.

     

    @Session public class MySessionBean {

    private DataSource customerDB;

    @Inject private void setCustomerDB(DataSource customerDB) {

    this.customerDB = customerDB;

    }

    public void myMethod (String myString) {

    ...

    Connection conn = customerDB.getConnection();

    ...

    }

    }

     

    The following example demonstrates a dynamic lookup with injection

     

    @Inject private void setSessionContext(SessionContext ctx) {

    this.ctx = ctx

    }

    ...

    myShoppingCart = (ShoppingCart)ctx.lookup(“shoppingCart”);

    ...

     

     

    Simplify CMP Entity Beans

     

    The open source Hibernate has become the darling for building the persistence layer for developers who have shunned entity beans for complexity, heavy weight and its limitations. EJB 3.0 is adopting a lightweight persistence model like Hibernate to simplify the container managed persistence. This will provide compelling reasons for EJB 3.0 CMP to become as the persistence model of choice for java developers. 

     

    Following are some of the compelling features considered for EJB 3.0:

    •  Entity beans will be reincarnated as POJOs
    • There will be no component interfaces required for entity beans
    • Improving modeling capabilities with support of inheritance and polymorphism
    • Make it usable and testable outside the container
    • Remove need for Dots for entity beans
    • Flexible support for O-R mapping
    • Major enhancements in EJB-QL. These are few niceties of SQL that EJB-QL is borrowing to satisfy the needs of enterprise.
    • Bulk update and delete operations
    • Projection list (SELECT clause)
    • Support for Group by, Having
    • Support Sub queries (correlated and not)
    • Additional SQL functions UPPER, LOWER, TRIM,etc..
    •  Dynamic queries 

    Also interesting to note that there is a plan to support native SQL queries with entity beans.

     

    Here is an example of a new entity bean looks like

     

     

    @Entity public class Employee{

    private Long empNo;

    private String empEmpName;

    @Nested private Address address;

    private Hashmap projects = new Hashmap();

    private Double salary;

    @PK(generated=true) public Long getEmpNo() {

    return empNo;

    }

    private void setEmpNo(Long empNo) {

    this.empNo = empNo;

    }

    public String getEmpName() {

    return EmpName;

    }

    public void setEmpName(String EmpName)j {

    this.EmpName = EmpName;

    }

    public Address getAddress() {

    return address;

    }

    public void setAddress(Address address) {

    this.address = address;

    }

    public Set getProjects() {

    return projects;

    }

    public void setProjects(Set projects) {

    this.projects = projects;

    }

    .public Double getSalary() {

    return salary;

    }

    public void setSalary(Double salary) {

    this.salary = salary;

    }

    ....

    }

     

     

     

    Testability Usability Outside Container

    Another major steps EJB 3.0 is taking to make EJBs usable/testable outside the EJB container. However greater details of this was not revealed in the presentation.

     

    Miscellenous Issues

    • The existing entity beans model (EJB 2.1) will still be supported.
    • EJB QL will be extended to support the old EJB models.
    • Container managed relationship may not be supported with new models.
    • Make Session Beans/MDBs as Service beans.

     

    Conclusion

    EJB 3.0 will be complete overhaul of the EJB technology and will be much simple and for developers. It will provide a lightweight persistence model like Hibernate that will provide a compelling persistence model for J2EE applications.


    12:23:15 AM    comment []

    © Copyright 2004 Debu Panda.

    PS: These are my own thoughts and not of my employer ..



    Click here to visit the Radio UserLand website.
     


    May 2004
    Sun Mon Tue Wed Thu Fri Sat
                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 31          
    Apr   Jun