cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Coming from EOF: Cayenne vs Hibernate
Date Wed, 11 Mar 2009 20:36:23 GMT
Comments inline ...


On Wed, Mar 11, 2009 at 4:06 PM, Francisco Peredo
<franciscoperedo@tabasco.gob.mx> wrote:
>
> Hi!


Hi Francisco.


> My first contact with an ORM was EOF... an ever since I have felt that
> nothing compares to it ;-).


I'm still doing WebObjects/EOF and have a decent idea about how the
two frameworks compare.  Cayenne is very similar to EOF (not
identical, but carries much of the spirit).  If you are familiar and
comfortable with EOF, it would probably be a fairly straightforward
and easy transition for you to use Cayenne (unless you do multiple
table inheritance, which Cayenne lacks).


> The thing is, I have had to work with JPA/Hibernate for a few years now...
> and I feel it has some weaknesses I really do not like, I am thinking about
> "switching to cayenne" but first i would like to be sure that Cayenne does
> not have this weaknesses too.
>
> List of weaknesses in JPA/Hibernate:
>
> -No way to manage an object that "will be persisted", in JPA/Hibernate if
> you call entityManager.persist(object) and the database does not support
> sequences (like MS-Sql) an insert will be triggered, and if any of the non
> nullable fields of the objects is null, it will crash. If your object has a
> compound primery key, things get worse, because the entityManager can not
> deal with it until the compound primary key is set, and if you compound
> primary key is formed by foreign keys pointing to objects that are new too,
> that means you will not be able to save stuff with with a simple single call
> to entityManager.persist to one of the objects, cascading will not help you
> (I really miss something "magic" like ObjectContext.commitChanges() )


Cayenne, like EOF, can use sequences or a PK table, but if you have
complex keys, you should write your own PK generator.  If a PK field
is null, Cayenne will attempt to assign it (and cascade where
necessary) using the PK generator, just like EOF.  If the PK is
non-null, Cayenne assumes you've provided your own PK (this is an
"easy out" over writing your own PK generator).


> -No easy way to know if "an object is dirty" (if it has changed/deleted
> since it was read from the database, there is just no API for that), and
> since you can not know what objects will be persisted, and what object have
> changed, and what objects will be deleted from database, that means you can
> not easily create an unified API for centralized polymorphic validation
> (that is no easy way to create validateForSave, or validateForDelete)


You can ask the Cayenne DataContext (similar to an EOEditingContext)
for deletedObjects(), modifiedObjects(), and newObjects().  You can
also call the object's getPersistenceState() method to see if it is
COMMITTED, DELETED, HOLLOW (a fault), MODIFIED, NEW, or TRANSIENT.


> -No real equivalent for validateForXXX, JPA lifecycle callbacks are not
> match for validateForXXX because you can not query the database during the
> lifecycle callbacks, and if you throw an exception inside a lifecycle
> callback, the JPA/Hibernate entityManager enters an invalid state, and after
> that you can not continue to use your POJOs, you have to start over with a
> fresh entityManager... and without you modifications to the POJOs. Note that
> Hibernate new validation framework does not offer a real solution for this
> problem... and AFAIK JSR-000303 will not help with this either.


Cayenne has validate methods and has added JPA lifecycle callbacks
(which I'm not too familiar with at this point).  Take a look at:

http://cayenne.apache.org/doc/dataobject-validation.html

and

http://cayenne.apache.org/doc/lifecycle-callbacks.html


> -No support for some kind of temporary id: In JPA/Hibernate, the id for an
> object is "null" until you flush it to the database, so if you need to
> reference a particular object instance from the user interface... there is
> plain no way to do it, you have to "save it first" to get a primary key.


Cayenne doesn't really have this, either.  (Neither does EOF.)  You
have to commit to have the PKs assigned (unless you assign them
yourself).  There might be a temporary ID, but it sounds like you are
asking about something more permanent that can be looked up later.


> Those are my main disagreements with the way I have to work with
> JPA/Hibernate... will switching to
> Cayenne help me with those? And if it works... here is a crazy idea... what
> if you guys developed a wrapper that could work on top of any JPA provider
> to offer a higher level EOF like API ?
>
> Regards,
> Francisco

Mime
View raw message