Technical Jargon

"Its fun to learn"- guru_G

Integration of Hibernate with Spring

Spring is a powerful middle tier framework which has got good support for Hibernate. In Hibernate we perform the operations like save,update,merge etc. using session. If we are using spring we can perform all these and many more tasks using Hibernate Template. In order to use Hibernate template(There are other ways too.I personally feel this is the simplest way) we need to define an interface containing all the methods of the DAO class. The DAO class must implement this interface and extends HibernateDaoSupport. By doing this we can perform all the operations. Advantage of using Hibernate Template is that it performs the session and transaction management by itself and we don’t have to implicitly open and close the session or begin and commit the transaction.

June 4, 2009 Posted by | Hibernate, Spring, Technical | , , , | Leave a Comment

HQL

Hibernate provides a simplified language for querying into the database. Its called HQL-Hibernate Query language.
We can use SQL Queries directly in hibernate,So naturally a question may come.Whats the need of using HQL if you can perform the same with SQL ?

1.HQL is very simple. Its very easy to learn and manipulate.
2. HQL engine generates the most appropriate SQL for a particular task from a set of SQL statements.
3.Usage of HQL will help in application portability. We can change the Database from say Oracle to MySQL without changing any HQL queries. Only change needed is in the Configuration file where we need to specify the appropriate driver and dialect.

These are some of the advantages of using HQL. I will keep you updated with more advantages soon.

May 24, 2009 Posted by | Hibernate, Technical | , , | Leave a Comment

Lazy Loading in Hibernate

Lazy loading is a functionality provided by Hibernate. What lazy loading does is that it doesn’t load the the associated objects for a class during startup. They will be loaded only when they are referenced. This lazy loading greatly improves the application performance. In hibernate 3.0, lazy loading is enabled by default. ie:by default the objects are only loaded as and when they are referenced. To say this in XML terms in hibernate 3.0 lazy=”true” by default for objects and lazy=”false” for collections. This default behavior of hibernate may throw in some exception called LazyInitializationException. This is a very famous exception and to whoomever you ask for an answer the default answers would be
1. setting lazy=”false” for all
2.Use session.get() instead of session.load.
:)
I don’t think the first one can be called a solution as setting lazy=”false” is like forcing the hibernate to work without one of its most important feature.Also it degrades the performance. If the no of tables and the underlying relations are huge, then it will take a hell lot of time to perform some task. So what we can do is to
keep lazy as true and load the associated objects as and when we need it.

[Please bear with me for the time being, i will post the examples for all these once ma IDE is working fine.Till then i will continue with the theory aspect of it.]

The second one is to be used whether or not u get a Lazy Exception.I say this because method load() returns an exception in case of a null object while method get() returns a null object in the same case. So its better to use session.get() for all cases. If you are so much interested in using session.load() do it if and only if you are sure that such an object exists.

Lazy Exception can be a hard nut to crack if you don’t understand the underlying reason of it. Lazy Exception can also occur due to improper session management ie: trying to access the session after closing it.

May 24, 2009 Posted by | Hibernate, Technical | , , | Leave a Comment

Pointers

Learn hibernate from Gavin King,Christian Bauer and team. They are the creators of hibernate. Recently i read about Gavin, he has only 5 years of experience working with Java and went on to create a framework of this magnitude.Infact knowledge of Java is not the essential thing you need to learn Hibernate.You have Nhibernate if you are a fan of .NET technologies. Gavin and Christian are presently working for the JBoss project and he is also an active member of the EJB spec. group.

Visit Hibernate home page Hibernate Core

Read the documentation .

There are also many tutorials available in the web. wait..!!! I am gonna post a tutorial in Hibernate where i will help you in each and every step of learning hibernate.

PS: I am having some problems with my Eclipse IDE. ie y the delay in posting the tutorial

May 23, 2009 Posted by | Hibernate | , | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.