aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 2.0: EJB QL + XDoclet = using EJB on more projects! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 2.0: EJB QL + XDoclet = using EJB on more projects!" Watch "EJB 2.0: EJB QL + XDoclet = using EJB on more projects!" New topic
Author

EJB 2.0: EJB QL + XDoclet = using EJB on more projects!

Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
I have recently read a lot of articles about whether or not developers 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. While I agree that EJB is not for every project, 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.
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 link above and follow the links 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. There are links to the files Peter created... just follow the link above.)

    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 yet. (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 rick_m_hightower@hotmail.com .)
    The code in the last two parts uses XDoclet, and makes a good example of how to use XDoclet to setup CMR relationships and write finder and select methods in EJB QL.
    Please let me know what you think about the article or EJB QL. I really want some feedback. Event if its feedback. Sometimes is the most constructive.
    [ June 24, 2002: Message edited by: Rick Hightower ]
    [ June 24, 2002: Message edited by: Rick Hightower ]

    Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    If you have used EJB QL, please state the app server you used it with.
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    Also, if you have used XDoclet please state what you used it for.
    Rick Salsa
    Ranch Hand

    Joined: Jul 17, 2001
    Posts: 173
    Hi Rick,
    First off, I must say thanks for the awesome book!! I've learned a lot from it.
    As for EJB-QL and CMP, I'm using it on a open source project that I'm working on at the moment (when I have time... ). We are also going to be using it on a few projects at work. I think its the cat's a@%!! It saves a lot of time and I don't have to worry about any JDBC. I also like the fact, that with most containers, all I have to do is tell it what datasource I want to use, and it takes care of the persistance for me!! No need to create a DAO interface and implementations for each db I want to run on. The container takes care of it for me with CMP.
    My only grip right now with EJB-QL is its lack of support with Date fields (like using LIKE functions on them) and the fact that you can't run an ORDER BY on them. I hear that they are working on that right now... Just means that you'll have to create a EJB-QL query to get around it.
    It's a big time saver!! I'm currently using it with JBoss, but plan on trying it out with JRun and Orion.
    As for XDoclet, I haven't had the time to play with it yet It looks very interesting and it will for sure save a lot of time. From what I've read about it, and from what you've mentioned, it will create all the deployment descriptors and any vendor specific files for you. Setup the build in ant and run specific deployments for each app server. Can't get much simpler than that. Makes the whole portability issue less of a pain in the butt.
    I plan on looking over the articles soon.
    Just my 2cents,
    /rick
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    Rick Salsa... I remember that name...

    As for EJB-QL and CMP, I'm using it on a open source project that I'm working on at the moment (when I have time... ). We are also going to be using it on a few projects at work. I think its the cat's a@%!!

    I really dig it too. We used it on a lot of projects. It saves a lot of time.

    My only grip right now with EJB-QL is its lack of support with Date fields (like using LIKE functions on them) and the fact that you can't run an ORDER BY on them.

    WebLogic and Resin support ORDER BY clause. Resin even supports it in the relationship definition so you can have an ordered relationship. Its in the EJB 2.1 Public draft.
    It's a big time saver!! I'm currently using it with JBoss, but plan on trying it out with JRun and Orion.

    I heard Orion does not quite support it yet, but this may have changed. You may want to try Resin.
    Resin Enterprise
    It supports it and it is a developer friendly app server that screams!

    As for XDoclet, I haven't had the time to play with it yet It looks very interesting and it will for sure save a lot of time. From what I've read about it, and from what you've mentioned, it will create all the deployment descriptors and any vendor specific files for you.

    And more... the only thing you have to create is the Bean implementation. It generates the rest, homes, local homes, remote interface, local interface, primary key classes, and much more.
    Now that I use XDoclet, I can't see doing EJB's without it.

    First off, I must say thanks for the awesome book!! I've learned a lot from it.

    Blushing.... Thanks for buying it and saying nice things about it.
    For anyone else who reads this post... Here is the book Rick Salsa is talking about.
    book site
    Rick Salsa, thanks for the amazon review for the book.
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    There is a similar conversation at the JavaLobby.
    EJB QL and XDoclet
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    What People Think of the Tutorial
    Achim from Germany writes: "I read your white papers "Introducing EJB-CMP/CMR" part 1 and part 2.... These papers are the best start for EJB.... Now I'm very interested in part 3 (and 4), but I can't find them on the developerWorks Homepage ..." (They are coming soon.)
    Pete from North Carolina writes: "I've been working through your "Introducing EJB-CMP/CMR" tutorials. Great stuff. Well presented - simple and straight forward. Really learning a lot. "
    Patrick from the U.S.A. writes: "Great Job on part 1 and 2 of your tutorial on CMP/CMR and EJB QL. When will part 3 and 4 be out.? Will it be able to run on JBoss Resin, and Orion." (It is done! It should be out soon, I am working on getting the example to work with Resin, JBoss. Part 3 and 4 works with WebLogic.--Rick)
    Rick Hightower
    Author
    Ranch Hand

    Joined: Feb 20, 2002
    Posts: 350
    BMP or CMP
    http://www.coderanch.com/t/309892/EJB-JEE/java/CMP-BMP-Platform-independant
    http://www.coderanch.com/t/309892/EJB-JEE/java/CMP-BMP-Platform-independant
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: EJB 2.0: EJB QL + XDoclet = using EJB on more projects!