• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate caveats, best practices and performance tuning

 
arulk pillai
Author
Ranch Hand
Posts: 3388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steven Doyle
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic