Introduction to Hibernate

Author posted by Jitendra on Posted on under category Categories Hibernate with Leave a comment on Introduction to Hibernate

Post by – Subhash Bhajankar

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 :

  1. Create JDBC Connection
  2. Connect Database
  3. Create SQL String dynamically by taking fields value one by one
  4. And also manage all transaction, Exception handling, rollback and commit Continue reading “Introduction to Hibernate”

Step By Step Hibernate Tutorial Using eclipse WTP

Author posted by Jitendra on Posted on under category Categories Hibernate, My SQL and tagged as Tags , with 30 Comments on Step By Step Hibernate Tutorial Using eclipse WTP

Step By Step Hibernate (ORM Tool) Tutorial Using eclipse WTP

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”

Eclipse Install New Software - Hibernate
Eclipse Install New Software - Hibernate

Continue reading “Step By Step Hibernate Tutorial Using eclipse WTP”

Servlet, Hibernate, jQuery and Ajax based google like chat

Servlet, Hibernate, jQuery and Ajax based google like chat with source code

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:

Servlet, Hibernate, jQuery and Ajax based google like chat
Servlet, Hibernate, jQuery and Ajax based google like chat

Continue reading “Servlet, Hibernate, jQuery and Ajax based google like chat”

Cause and solution of “org.hibernate.LazyInitializationException: could not initialize proxy – no Session” error

Cause and solution of “org.hibernate.LazyInitializationException: could not initialize proxy – no Session” error

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. Continue reading “Cause and solution of “org.hibernate.LazyInitializationException: could not initialize proxy – no Session” error”