How to best use Hibernate

S

Snyke

Ok I have a business application which has persists its data to a
database using hibernate. What I want to know is what is the best
practice for persistence?
- Load it all into memory and then synchronize to the database.
- Load only parts out of the persister, modify it and then save it
back to the database.
- Hybrid of those, loading into memory changing it there,
synchronizing it to the database but leave the data in memory so I
don't have to reload it again.

Obviously the last option has a lot of overhead, because of its dynamic
loading, the first is my preferred one, but am I using all the
potential of Hibernate, and is the effort managable for lots and lots
of data? The second is what looks like a standard solution, but doesn't
the Hibernate stuff add a lot of overhead to this one too?

Thank you for your time,
Christian 'Snyke' Decker
http://www.Snyke.net
 
A

Arvind

Snyke said:
Ok I have a business application which has persists its data to a
database using hibernate. What I want to know is what is the best
practice for persistence?
- Load it all into memory and then synchronize to the database.

Depends on what "all" represents i.e. the underlying datastructure. For
e.g. if you are updating a tree structure of objects, does all
represent the entire tree, or a leg of the tree that matches the update
condition ?
- Load only parts out of the persister, modify it and then save it
back to the database.

Same question as above.
- Hybrid of those, loading into memory changing it there,
synchronizing it to the database but leave the data in memory so I
don't have to reload it again.

When manually done, the potential for buggy code is quite high in this
style.
Obviously the last option has a lot of overhead, because of its dynamic
loading, the first is my preferred one, but am I using all the
potential of Hibernate, and is the effort managable for lots and lots
of data? The second is what looks like a standard solution, but doesn't
the Hibernate stuff add a lot of overhead to this one too?

Hibernate does take care of the hybrid quite nicely, goes well with
many web frameworks, provides caching, takes care of create/update
scenario etc. Works quite well for us.

There are also other options like Castor etc that provide Object to DB
mapping via configuration and away you go writing business logic,
leaving the worrisome db coding, connection management etc to these
frameworks.
 
C

Chris Smith

Snyke said:
Ok I have a business application which has persists its data to a
database using hibernate. What I want to know is what is the best
practice for persistence?
- Load it all into memory and then synchronize to the database.
- Load only parts out of the persister, modify it and then save it
back to the database.
- Hybrid of those, loading into memory changing it there,
synchronizing it to the database but leave the data in memory so I
don't have to reload it again.

Obviously the last option has a lot of overhead, because of its dynamic
loading, the first is my preferred one, but am I using all the
potential of Hibernate, and is the effort managable for lots and lots
of data? The second is what looks like a standard solution, but doesn't
the Hibernate stuff add a lot of overhead to this one too?

First of all, Hibernate doesn't add "a lot" of overhead to very much.
The product writes nearly optimal SQL in most cases (some minor
exceptions, such as outer joins with PostgreSQL pre-8.2 as was pointed
out to me recently). Certainly the computational work of Hibernate
itself is trivial next to talking to a database.

Next, how much you modify prior to updating the database should be
determined first and foremost by the transactional boundaries of the
application. Hibernate has plenty of nice caching options, so you don't
need to let database performance issues dominate your system
architecture by trying to load and keep all this data in memory
intentionally. The cache does that. You can just write code to do what
you want.

That's the best I can do from your question. You'll get better answers
if you're more specific.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top