On Sep 6, 2010, at 9/61:47 PM , Borut Bolčina wrote: > Hello Joe, > > I just recently began two projects based on Hibernate (and Tapestry 5), so I > have limited knowledge to compare, but some of the differences immediately > showed up: > > 1.Code Life cycle > If you have the luxury to start a project with no database schema, then in > Hibernate you can start with POJOs, annotate them, create database on the > fly (just by configuration) and make changes in code only. Another approach > is to create an ER model (in MySQL Workbench for example), forward > engineer/synchronize with the database and later create JAVA code with the > Hibernate tools in Eclipse. But the tool is limited, you have to correct > some output by hand. If you make lots of changes in the auto generated class > and if you make changes in your favorite ER modelling tool and make changes > to the database with this tool, then you have to re-generate java code at > least a few times and than means you have to re-generate this code to some > other package (I use com.acme.entities.generated) and make local merge of > the old POJOs with the new ones. It doesn't consume much time, but with > Cayenne you have auto-generated classes and subclasses where you put your > business logic. I like the Cayenne approach, but I never got used to Cayenne > modeler, since ot does not offer a graphical way of drawing or displaying db > artifacts (ER model). If one prefers to start a fresh db design with his/her > favorite ER modeling tool, then with Cayenne you reverse engineer the db > schema with the modeler (the db engine must support constraints for > relationships to appear in the modeler). When rev-engineered and not > satisfied with the names of the relationship names (as was the case before > smart naming strategy) you had to correct each one in the modeler and then > (re)create the java classes. But since only the "auto" classes are > (over)written no harm is done, except for the compiler errors which > immediately show the location of offending method names. If one wants to > have ER model, Cayenne model and the code itself in sync there is a lot of > discipline to commit to. I think this is easier with Hibernate POJOs/Eclipse > Hibernate Tools/ER modeler, at least you don't have to deal with two GUI > tools. I would love to hear how other manage the life cycle - code/model > modifications. I do not have much experience starting with an existing > database - I guess I am the lucky one :-) >
:) Personal preference on this one, I guess. I've never much cared for ER diagrams. They're pretty, but I personally find the CayenneModeler's approach a faster way to work... usually. ;) > 2.ObjectContext versus Session > This one was a really bad surprise when started with Hibernate. Object life > cycle is much more natural with Cayenne. My first Lazyloading Exception > emotion was: "What the hell am I doing wrong?". Then I realized that I can > not follow the relationships if not eagerly fetched. _______ (insert some > ugly word). A big plus for Cayenne here. I was told that Seam framework has > solved the LazyLoadingException. Is this correct? > I've heard it helps. Gavin is a committer on the Seam project, is he not? Still strikes me as odd that it requires an "application level framework" to cover up what is, IMO, an ORM-level hole. :) > 3.POJO versus DataObject > I haven't found a downside with my persistent objects inheriting from > DataObjects. POJO hype? > Definitely agree. > 4.Bidirectional relationships > Associations in Hibernate are not inherently bidirectional as are in > Cayenne. According to Hibernate book this is considered a good thing. Quote: > "POJO oriented persistence engines such as Hibernate don't implement managed > associations. Contrary to EJB 2.0 CMR, Hibernate and JPA associations are > all inherently unidirectional. As far as Hibernate is concerned, the > association from Bid to Item is a different association then the association > from Item to Bid! This is a good thing - otherwise your entity classes > wouldn't be usable outside of a run time container.". I don't think this is > a valid reason - you can use Cayenne in whatever environment you want and it > manages the bidirectional relationships for you. > To be fair, you /can/ make bi-directional properties. But it's the difference in defaults: Cayenne defaults to bi-directional; hibernate to unidirectional, and it requires much more work in hibernate to make the properties bi-directional. To make them "unidirectional" in cayenne requires deleting the corresponding property/mapping. ;) > 5.Documentation > Hibernate wins here totaly. Not only it gives confort to developers and > managers, the book "Java persistence with Hibernate" really teaches you > techniques and good practices. Also gives some recipes and anti-patterns. > Cayenne will stay marginal if no book goes to print. > I confess, I don't have Java persistence with Hibernate (I should probably buy it, but I can't bring myself to contribute $$ to the hibernate ecosystem ;). The hibernate online docs are, in a sense, more complete than the cayenne docs. But the cayenne docs are, to me, at least, more /informative/. Also, I find cayenne much more /intuitive/. So, whereas I'm constantly frustrated with the hibernate online documentation, I haven't felt that way toward cayenne. ;) But that's an individual thing, and YMMV. Certainly, there are books for Hibernate, at once a consequence and cause of its success. > 6.Integration to other frameworks > Hibernate wins here also. There are a number of frameworks which integrate > with Hibernate, just google "hibernate integration". Where is my long > awaited T5.2-Cayenne bridge? :-) > Check out the trunk source? It's compatible with T5.2. At least, I have projects that are running with T5.2 and the latest t5cayenne source. :) Sorry, I've been crazy busy lately and haven't had time to put together a real release. But the code has made some nice progress in the last 6 weeks or so, including T5.2 compatibility and improved ValueEncoder support (trunk adds support for multi-key PK's. Take that, tapestry-hibernate! ;). I'm also planning on either updating the EntityField, or creating an alternative component (and deprecating EntityField) that works better. I have a working prototype of said new component in a personal project I'm working on, but it still has a couple of quirks that I need to fix before moving it directly into T5cayenne. Robert > These are just first observations I encountered during first two months of > using Hibernate. > > Regards, > Borut > > > 2010/9/5 Joe Baldwin <[email protected]> > >> Hi, >> >> I am again responsible for making a cogent Cayenne vs Hibernate Comparison. >> Before I "reinvent the wheel" so-to speak with a new evaluation, I would >> like to find out if anyone has done a recent and fair comparison/evaluation >> (and has published it). >> >> When I initially performed my evaluation of the two, it seemed like a very >> easy decision. While Hibernate had been widely adopted (and was on a number >> of job listings), it seemed like the core decision was made mostly because >> "everyone else was using it" (which I thought was a bit thin). >> >> I base my decision on the fact that Cayenne (at the time) supported enough >> of the core ORM features that I needed, in addition to being very similar >> conceptually to NeXT EOF (which was the first stable Enterprise-ready ORM >> implementations). Cayenne seems to support a more "agile" development >> model, while being as (or more) mature than EOF. (In my opinion. :) ) >> >> It seem like there is an explosion of standards, which appear to be driven >> by "camps" of opinions on the best practices for accomplishing abstraction >> of persistence supporting both native apps and highly distributed SOA's. >> >> My vote is obviously for Cayenne, but I would definitely like to update my >> understanding of the comparison. >> >> Thanks, >> Joe >> >>
