Hi Pradeep,

You are asking a loaded question and there will be varying opinions of
advantages from different people and their use cases.  That being said,
here are my top-three:

1. Cayenne Modeler

I prefer modeling and mapping my database to Java using a graphical tool.
Perhaps that is because I got started with NeXT's Enterprise Objects
Framework years ago.  To me it is just a more pleasant way of creating the
model.  I don't know of a UI for Hibernate.


2. Templated Class Generation

Once your model starts becoming more complex, the ability to create custom
class templates to generate your Java code is a nice feature to have
available.

Also, because Cayenne uses the Generation Gap [1] pattern, you are dealing
with the exact classes you have in your code base.  If you have a User
class in your code, you have an instance of User at runtime.  In Hibernate,
you have a proxy class that mimics a User class, but with hidden Hibernate
bits added in.  Hibernate claims to be POJO, but with the proxies it kind
of inverts the subclassing style used by Cayenne and can make some code
more difficult.


3. Object Context

This could easily be my #1 feature.  Cayenne's Object Context is a
logically defined unit of work and all Cayenne model objects reside in
one.  When you are done making changes to your object graph, you tell the
Object Context to commit changes to the database.  The Object Context then
evaluates everything that changed, begins a transaction, issues all of the
INSERT, UPDATE, and DELETE statements, and commits the transaction.  You
don't tell individual objects to do it (such as Hibernate's saveOrUpdate()
method).  You work at a higher level.

This may not seem like a big deal, but when you are dealing with complex
graphs it is.  I worked on a financial application which could have
thousands of model objects (and over 10k data points) with hundreds of
relationships for the user to edit.  The UI allowed the user to make
changes to any part of the object graph they wanted (and run business rule
validations over the entire object graph).  Whenever they were ready, they
would click the "Save Changes" button.  The backend code was an
objectContext.commitChanges() call, wrapped inside a try/catch to handle a
database error.  You can continue using this Object Context, too, making
more edits and committing changes repeatedly.  If I were using Hibernate,
I'd have to track all the changes myself (re-attaching objects to a
new/valid Hibernate session and calling the right save/delete type methods)
and it would've been quite difficult to get it right and maintain the logic
as the model changed.  I prefer to let the Object Context handle all of
this for me.


4. Mailing List (bonus since it isn't part of the Cayenne code)

We try to be friendly/helpful here.  The creator of Cayenne will never call
you an idiot, for example.


There are many more reasons, such as Optimistic Locking on actual data
instead of an arbitrary version number, no LazyInitializationException,
rarely (at least in my usages) having to write SQL-like statements in
Strings (which is re-factor unfriendly), etc.

mrg

[1] https://en.wikipedia.org/wiki/Generation_gap_(pattern)


On Wed, Dec 4, 2019 at 7:27 AM Pradeep Ghanto (V) <pgha...@apple.com.invalid>
wrote:

> Hi Team,
>
> Could you please send out the highlights of Apache Cayenne and advantages
> of using it over Hibernate?
>
>
> Regards,
> Pradeep Ghanto

Reply via email to