Nearby lessons
2 of 19Hibernate - Installation and Setup
- Understand Hibernate - Installation and Setup
- See working code examples
- Learn from common mistakes and Q&A
Learn Hibernate - Installation and Setup step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.
Eclipse
- Home: IBM canada [Initially]
- Eclipse Foundations [2003]
- website: www.eclipse.org
- Objective: To simplify JAVA/J2EE application Development.
- Initial Version: Ecplise3.0[2004]
- Used Versions:Eclipse3.5,3.6,3.7[Helios,Gelilio,Indigo]
- Latest Version: Ecplise4.2[1st march,2013][JUNO]
- Eclipse4.3.1[26 june,2013][Kepler] ii. Eclipse4.4[9th Aug,2013][Luna] iii. Eclipse4.5[Mars] iv. Eclipse4.6[Neon]
- Eclipse4.7[Oxygen]
- Designed on: Java platform.
- Type: Open Source Software.
Installation Process
- download eclipse-jee-oxygen-1a-win32.zip
- extract eclipse-jee-oxygen-1a-win32.zip file at the required location.
- After step 2 , we will find "eclipse" folder ie installation folder.
- Double click on eclipse icon available at c:\eclipse\ location.
- After step4, we will get a window to select workspace, where specify the location where
we want to manage all the applications.
Steps To Design Hibernate Applications in Eclipse IDE
- Prepare Java Project.
- Prepare Hibernate Library and Add that library to Appl.
- Prepare PJO class.
- Prepare Mapping File.
- Prepare Configuration File
- Prepare Client Application.
- Run Client Application.
Prepare Java Project
I. Right Click on "Project Exproer". II. Select "New" III. select "Java Project" IV. Provide Project Name : app1 V. Click on "Next" button. VI. Click on "Finish" button.
Add all hibernate Library to Java Application
1) Right Click on "Project". 2) Select "Properties". 3) Select "java build path". 4) Select "Library". 5) Select "Add Library". 6) Select "User Library". 7) Click on "Next" button. 8) Click on "User Libraries". 9) Click on "New" button. 10)Provide User Library Name : Hibernate3_Lib". 11)Click on "OK" button. 12)Select User Library "Hibernate3_Lib". 13)Click on "Add External Jars". 14)Select the following JAR files mandatorarily.
- ojdbc6.jar
- hibernate3.jar
- jta-1.1.jar
- commons-collections-3.1.jar
- dom4j-1.6.1.jar
- javassist-3.12.0.GA.jar
- antlr-2.7.6.jar
- slf4j-api-1.6.1.jar
- hibernate-jpa-2.0-api-1.0.1.Final.jar
15)Click on "OK" button 16)Click on "Finish" button. 17)Click on "Apply" and "OK" button.
Prepare POJO class
1) Right Click on "Src" folder. 2) Select "New". 3) Select "Class". 4) Provide package Name:com.durgasoft.hbn.pojo 5) Provide class Name: Employee 6) Click on "Finish" button. 7) Declare Properties in the generated class. 8) Generate SetXXX() and getXXX() methods. a) Right Click b) Select "Source". c) Select "Generate Getters and Setters". d) Select "Select All". e) Click on "OK" button.
- package com.durgasoft;
- public class Employee{
- private int eno;
- private String ename;
- private float esal;
- setXXX() and getXXX()
Prepare Mapping File
1) Right Click on "Src" folder. 2) Select "New" 3) Select "Package". 4) Provide Package Name"com.durgasoft.hbn.mappings" 5) Click on "Finish".
- Right click on "com.durgasoft.hbn.mappings" package.
- Select "New"
- Select "other"
- Select "XML"
- Select "xml file"
- Click on "Next" button.
- Provide File Name: Employee.hbm.xml
- Click on "Next"
- Click on "Next"
- Click on "Finish" button.
- Provide <!DOCTYPE..> tag from hibernate3.jar file under the package org.hibernate from
hibernate-mapping-3.0.dtd and past in the mapping file.
Prepare Configuration File
1) Right Click on "Src" folder. 2) Select "New" 3) Select "Package". 4) Provide Package Name"com.durgasoft.hbn.cfgs" 5) Click on "Finish".
- Right click on "com.durgasoft.hbn.cfgs" package.
- Select "New"
- Select "other"
- Select "XML"
- Select "xml file"
- Click on "Next" button.
- Provide File Name: hibernate.cfg.xml
- Click on "Next"
- Click on "Next"
- Click on "Finish" button.
- provide <!DOCTYPE...> tag from hibernate3.jar file from org.hibernate package from
hibernate-configuration-3.0.dtd.
Prepare Client App
1) Right click on src 2) Select "New" button. 3) Select "Class". 4) Provide package Name: com.durgasoft.hbn.test 5) Provide Class Name : ClientApp 6) Select "select public static void main(String[] args)" check box. 7) Proivide Application logic inside main() mnethod.
Run the application — Employee.java
- Right click on ClientApp.java
- Select "Run As".
- Select "Java Application".
Note: Download JAR files from https://sourceforge.net/projects/hibernate/files/hibernate3 Hibernate Applications
Example:
Run the application — Employee.hbm.xml
Run the application — hibernate.cfg.xml
Run the application — ClientApp.java
Run the application
In Hibernate Applications, when we access persistence methods , Hibernate Software will take that persistence method call and it will prepare databse dependent native sql query on the basis of hibername mapping details and configuration details . In this context, to display the generated database dependent sql query on console we have to use "show_sql" property with the value "true" in hibernate configuration file.
Example On Hibernate SaveOrUpdate(--) method — Employee.java
Example On Hibernate SaveOrUpdate(--) method — Employee.hbm.xml
Example On Hibernate SaveOrUpdate(--) method — hibernate.cfg.xml
Example On Hibernate SaveOrUpdate(--) method — ClientApp.java
Example to delete records from DB — Employee.java
Example to delete records from DB — Employee.hbm.xml
Example to delete records from DB — hibernate.cfg.xml
Example to delete records from DB — ClientApp.java
Example To retrieve Record from DB — Employee.java
Example To retrieve Record from DB — Employee.hbm.xml
Example To retrieve Record from DB — hibernate.cfg.xml
Example To retrieve Record from DB — ClientApp.java
- Key ideas of Hibernate - Installation and Setup explained simply
- Ready-to-use code examples
- Exam-style questions at the end