Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

How to best use Hibernate

Thread view: 
Snyke - 09 May 2006 23:27 GMT
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
Arvind - 10 May 2006 00:03 GMT
> 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.

--
Arvind
Chris Smith - 10 May 2006 05:43 GMT
> 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
[quoted text clipped - 11 lines]
> 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.

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.