EJB QL + XDoclets = more EJB on more projects

I have recently read a lot of articles about whether or not developer should use EJB.


The argument against EJB tends to be that they are too complex. This is ironic since EJB's purpose was to simplify server-side development. Don't get me wrong... I agree EJB is too complex with for a lot of projects. Too many developer's were using EJB to add an extra bullet on their resume. While I agree that EJB is not for every project, I think recent advances in tools and techniques equate to EJB being more applicable to more projects.


Of particular interest in developer productivity with EJB is CMR, EJB QL and Xdoclet (EJBDoclet). Basically, the productivity and utility of these tools have to exceed the inherent difficulties in using EJB in order for EJB to be considered on a project. These tools lower the bar while increasing the utility and make more projects candidates for EJB.


Xdoclet, and open source project, simplifies EJB development by using JavaDoc API and some additional APIs as a code generator so that a developer only has to maintain one file instead of 5 or more files (,i.e., deployment descriptor, local interface and/or remote interface class files, local home and/or remote home class files, vendor deployment descriptors and/or conf files, bean implementation, primary key class files, value class files and more.)


There is a significant increase in productivity by using select methods and EJB QL. Code that use to take 10, 20, 30 lines of code can be written in just a few lines of code by mastering EJB QL.


When you combine Xdoclet simplification with EJB-QL and CMR, you can use EJB on a lot more projects.


With CMR it is really easy to work with the standard collections API (which we all know and love) when dealing with one-to-many and many-to-many relationships between entities.


EJB 2.0 specification has been out for a while. Have you tried the new features like CMR and EJB QL? If so, what do you think?


My personal experience is that finder and select methods (written in EJB QL) are really productive and can save a lot time. Is EJB QL the killer tool?


If you have not tried CMR or EJB QL, I wrote a tutorial on CMP/CMR and EJB QL that I think you should check out. The tutorial is on IBM developerWorks. Please go to this link to find out more information on this tutorial series and related articles.

Go to developerWorks and download the first two tutorials.


The free tutorial is broken up into four parts.


The first part describes basic EJB 2.x CMP with a simple finder method defined in EJB QL.


The second part describes defining EJB CMR relationships. Three types of relationships are covered:


  • Many to Many
  • One to Many
  • One to One


Both unidirectional and bidirectional relationships are covered.


The third part describes basic EJB QL. It mostly deals with joining cmr fields and working with IN and MEMBER OF.


The fourth and final part describes advanced EJB QL, and how to create select methods. The tutorial refactors code using the select methods and show a 10x reduction in code. (And gives directions how to rewrite a method from the earlier examples with a 20x reduction in code.)
Master select methods and you will love EJB QL!!


You can download the PDF files for the tutorial from developerWorks and view the tutorial offline. Or you can view it online. (see the links above to developerWorks)


Parts 3 and 4 are done. They should be out really soon. They have been bounced back and forth a few times between me and the editor. There is also an article in the works on XDoclet and EJBDoclet (more on this later).


The code in the first two parts works with Sun's RI for J2EE (RI is the reference implementation). Peter Luellen from West Side Widgets created the deployment descriptors to get final code from part 1 and 2 working for JBoss. (JBoss is an open source EJB application server.)


The code in the last two parts of the tutorial were done in WebLogic. The code will run on JBoss, Resin and more shortly. Check back at my site to see code updates to other app servers, and to see if the XDoclet article has been published. (Also if you would like to run the examples on your favorite app server, and send the configuration and/or code updates, I will glady accept them. Send them to [EMAIL PROTECTED])


The code in the last two parts uses XDoclets, and makes a good example of how to use XDoclets to setup CMR relationships and write finder and select methods in EJB QL.


Rick Hightower
Chief Technology Officer
Trivera Technologies, LLC.
Phone:520-290-6855
Fax:520-290-4179

Reply via email to