Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Hibernate caveats, best practices and performance tuning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate caveats, best practices and performance tuning" Watch "Hibernate caveats, best practices and performance tuning" New topic
Author

Hibernate caveats, best practices and performance tuning

arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3223
Form my experience it is easy to get started with Hibernate but for commercial use there are number of caveats, best practices, and performance tuning strategies to be aware of.

E.g. When to use hibernate and when not to, Lazy loading vs Eager fetching, ThreadLocal session pattern, object identity versus database identity, Making sure that connections and statements are closed properly, tuning the hibernate mapping file,etc

Does your book cover these aspects?


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Well, I simply couldn't agree with you more!

I've worked on alot of Hibernate projects, or come into Hibernate projects and they were just a mess. The reason was simple - people were getting Hibernate to do something they wanted it to do, without any real understanding of how to use Hibernate properly. As such, people were calling update when it wasn't needed, doing refreshes for no apparent reason, eagerly loading when it wasn't necessary, and opening sessions and committing transactions way too often.

One of the biggest problems with Hibernate projects is that people don't really understand how Hibernate works. That's really the big thing that my book does - it helps people understand how Hibernate works, and what Hibernate does between opening a session and closing a session. With that type of a strong foundation, people begin to understand when they need to load eagerly, or when they need to open or close a session.

So, one of my goals with the book is not to merely get people up and running with Hibernate, but to also show them how to use the technology properly. As such, best practices naturally make their way into persistence project, people make good decisions about fetch types and loading strategies, there are fewer problems during the development cycle, and when problems do arise, they can be solved quickly by competent and knowledgeable Hibernate developers.

Kindest regards,

-Cameron McKenzie
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3223
So, one of my goals with the book is not to merely get people up and running with Hibernate, but to also show them how to use the technology properly.


Excellent.
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

In your example :
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=04CRUDcreateretrieveupdatedeletewithhibernate



In the above code why we need transaction commit? we are just fetching the data. Please clarify me.


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Steven Doyle
Greenhorn

Joined: Jun 28, 2005
Posts: 1
I'm guessing they're using the thread current_session_context_class which will start or return the session and transaction for you when you call getCurrentSession(). Instead of committing the transaction and closing the session you can just commit which will close the session for you also. Regardless, you are always within a transaction when you perform selects even if your database autocommits - nothing happens against a database without a transaction.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate caveats, best practices and performance tuning