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
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.
Joined: May 31, 2007
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.
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.
subject: Hibernate caveats, best practices and performance tuning