Tuesday, October 18, 2011

Download Hibernate Sample Programs

Hi Every one, Here I would like to share some of the hibernate concepts with sample programs.You can download the sample programs built using eclipse 3.4. Please follow the instructions given to download, install and run the sample programs. This demo covers the following topics.

1. Hibernate with xml mapping
2. Hibernate with annotations
3. Hibernate with Spring
4. JPA on top of Hibernate
5. JPA on top of Hibernate with Spring

Here we go..,
Here you can download the sample programs from any one of the following links.Both the links refer to the same sample programs.

Link 1 Hibernate-Demo.zip

Link 2 Hibernate-Demo.zip

Steps to install and run the Hibernate-Demo

Step 1:
Unzip the downloaded zip file into any of your favorite location other than your current eclipse workspace location. For example , unzip the file to C:\Hibernate-Demo.

Step 2:
Create a new project in eclipse as follows.
a) Create project by clicking File-->New-->Project-->Java Project
b) In the New Java Project window, select the
Create project from the existing source radio button.
c)
Browse to the location where the downloaded project has been installed and select the folder.
d) Name the Project Name field and click Finish.


Step 3: Start and Run the HSQL DB. For this demo, we have chosen to use the HSQL (1.18) as the database. Here are the steps to start the HSQL DB.
a) Open two command windows and go into the folder where the downloaded project is unzipped.(i.e) to the location where the hsql.jar is located.

b) Run the command java -cp hsqldb.jar org.hsqldb.Server to start the HSQL DB in one window. For example , c:\Hibernate-Demo> java -cp hsqldb.jar org.hsqldb.Server



c) Run the following command in another command window,
java -cp hsqldb.jar org.hsqldb.util.DatabaseManager , to open the DB Manager window to view and execute the SQL commands. For example c:\Hibernate-Demo> java -cp hsqldb.jar org.hsqldb.util.DatabaseManager


d) In the HSQL DB manager window, select the HSQL Database Engine Server from the Type drop down list and click OK. By default there is no password for HSQL DB.


You will now see a console where you can execute the sql commands and view the results.



Start Exetuting the Sample programs:

Now , we are all set ready to execute the sample programs that are available from every package. Execute those classes from every package that has the main method in it.

Once the classes are executed ,
a) Check the eclipse console window for the output generated.
b) Run the simple select queries in HSQL database manager on those tables that are involved in the program.


You will now be able to understand the logic involved in persisting the objects using hibernate.