What is the problem that hibernate is trying to solve?
Let’s take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running application We would have lots of such objects in memory, What if I restart my application ? Everything will be lost. So to overcome this problem and persist data inside my application i will save it in Database.
As shown in below image every object in Java will be represented as single row. Here, class corresponds to table and object of class corresponds to row. This was something that we were been doing over the year (Off course before ORM Tool).
Normal approach to save data in Java is something like :
Create JDBC Connection
Create SQL String dynamically by taking fields value one by one
And also manage all transaction, Exception handling, rollback and commit
Hibernate is the ORM tool widely used in java community to persist the java object using Object Relational Mapping (ORM) concept. ORM reduces number of lines to interact with database with optimized query language which is Hibernate Query language (HQL).
In this example, we will create a simple login application using hibernate tool of eclipse. We will use eclipse WTP (Web Tools Platform), to install “Hibernate Tools”. Follow below steps :
In Eclipse IDE, menu bar, select “Help” >> “Install New Software …” put the Eclipse update site URL “http://download.jboss.org/jbosstools/updates/stable/helios”
Hi, In this article, my aim is to create an application which uses the concept of Hibernate in Servlet with Ajax support of Jquery.
Below figure can give you the idea of final look and feel of the complete application:
In Hibernate, a common error faced by lots of developer is “org.hibernate.LazyInitializationException: could not initialize proxy – no Session“. In lots of forum the answer is no answer and most of forum have answer but there is no explanation for the beginners.
First, Lets reproduce this error in Hibernate.
Assume that Hibernate configuration (hibernate.cfg.xml) and mapping file is already written.