« Dot-Net vs. Java... | Main | Hibernate tests in... »

Ready to Hibernate.

Finally, I'm ready to start working on the Hibernate implementation of the Roller Weblogger backend. I ended up doing a lot more refactoring than I had intended. I told you about how I moved code from the Castor implementation into abstract base classes that can be used by the Hibernate implementation. Now I'll describe the changes that I made in the Roller build and code-generation process.

In the original Roller build process, illustrated in Figure 4 of the article Building a J2EE Weblogger, I used abstract javax.ejb.EntityBean classes as the meta-data basis for generating code via the XDoclet EJBDoclet task. I was subverting EJBDoclet: using it to generate Data Objects, Struts Forms, and Castor mappings but not using any of it's EJB output.

That worked pretty well, but eventually it became a problem. The generated Data Objects were just dumb data-holders and, over time, we realized that they need to be smarter "business objects." The Data Objects were regenerated on every build and that made it diffucult, if not impossible, to add new methods, new logic, and new collections.

The new Roller build/code-gen process

<img src="http://www.rollerweblogger.org/resources/roller/xdoclet-roller-sm.jpg" alt="Diagram of Roller build process">

The new Roller build process, or at least the code-generation part of it, is shown above. We now start with some hand written "Plain Old Java objects" or POJOs. We still have to subvert EJBDoclet because the XDoclet <strutsform> and <castormapping> can only exist inside EJBDoclet.

I had to use Matt Raible's patched version of <strutsform> (from his struts-resume example) because the one in XDoclet 1.2b2 works only if the source class extends javax.ejb.EntityBean and the new Roller POJO's don't do that. Matt and I consider this to be a bug in EJBDoclet, but I'm not sure the XDoclet guys agree. Maybe Roller should define it's own <strutsform> that works on any POJO and that inserts validator tags (something Matt also added in his struts-resume example).

The Roller build/code-gen process is still not perfect, but it's "good enough" for me to begin my Hibernate implementation of the Roller Business Tier interfaces. I'll be blogging as I go so stay tuned.

Comments:

Any particular reason you're not use EJB and CMP? I've just started using J2EE and JBoss in particular and have found its CMP engine very good so far.

Posted by Alex Hornby on March 02, 2003 at 03:14 PM EST #

Maybe you could list some reasons that we should switch from using a persistence framework (i.e. Castor or Hibernate) to EJB Entity Beans.

Posted by Dave Johnson on March 02, 2003 at 03:17 PM EST #

I'm the first to admit that I'm only a beginner at J2EE, but I've found the JBoss entity bean CMP stuff good because: * xdoclet supports it directly - so only one source file to write/maintain. Also autogenerates extras like data transfer objects etc. * its seems dead quick - totally subjective of course but may be related to features below. Even seems competitive with C++/ODBC ( which perhaps says more about the state of ODBC drivers :^) * has read ahead support - so doesn't seem to hammer the db with single queries. * entity beans have a lot of doco for them - I've found it easy to pick up and several good example projects. (the JBoss template project is very simple to understand).

Posted by Alex Hornby on March 02, 2003 at 03:30 PM EST #

Here are some reason that I stopped using EJB: * Slower. I originally implemented Roller with EJB and found that it was very slow, even with the recommended patterns. I was using the Borland EJB Container out-of-process. Maybe things have changed now and maybe JBoss is faster, especially in-process. * Requires more work: more APIs to learn, more descriptors to generate, different DB mappings for each container supported, another container to support, maintain, document with install instructions, etc. * More expensive. ISPs typically charge more for an EJB container, even if the container is JBoss. My ISP charges close to $50/mo and I rather stay close to $20/mo. * Uses more memory. We've been trying to reduce the memory footprint of Roller and I don't think adding an EJB container is going to help reduce memory usage. That said, I'd like to see an EJB CMP implementation of the Roller backend, as long as it can co-exist peacefully with the other implementation(s) and it does not require any javax.ejb.* classes in the presentation tier. I'd like to benchmark it against Castor and Hibernate.

Posted by Dave Johnson on March 02, 2003 at 04:12 PM EST #

I just want to add a comment. Hibernate really rocks: - Its easy since you use POJO - Good xdoclet support (for hibernate 1.2.x) - Less overweight than EntityBean/CMP. I'm the author of xPetstore, a xDoclet version of Sun petstore application, and I have implemented 2 versions with the EXACT same functionality: - #1: JSP, Struts, EJB+CMP2.0 - #2: Velocity, Webwork, POJO+Hibernate #1 has ~165 .java files and ~3500 line of code. #2 has 33 files and 950 line of code.

Posted by Herve Tchepannou on March 03, 2003 at 06:49 PM EST #

Would you care to comment on your impression of the tradeoffs each corresponding alternative? jsp vs velocity struts vs webwork ejb+cmp vs. hibernate I'm currently developing with hibernate, struts, jsp. I have to agree that hibernate is very, very good at what it does. I find the jsp vs. velocity comparison to be hard to nail down. With the combination of JSTL and good use of taglibs and xdoclet, the JSP option can give you a very nice view environment. Velocity, otoh, is quite simple to use and possibly more easily understood by designers who aren't also developers. I can't comment Struts/WebWork except to say that I like Struts very much, and that a recent cursory look at WebWork left me with the impression that it is well worth further investigation.

Posted by Ken Pelletier on November 15, 2003 at 09:10 PM EST #

Struts by itself was totally less than productive. But now, Struts + JSP + "JSTL" == winning combination.

Posted by Albert on January 08, 2008 at 08:56 PM EST #

Post a Comment:
  • HTML Syntax: NOT allowed

« Dot-Net vs. Java... | Main | Hibernate tests in... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Roller, some may be related to this entry.