Sie sind auf Seite 1von 39

Hibernate

• Hibernate handles all of the Low-level SQL


• Minimize the amount of JDBC code
• Hibernate provides the Object Oriented Model
What is Hibernate?
• Hibernate is an Object-Relational Mapping (ORM) tool for the Java
language. That means you can map Java classes to database tables
and map Java data types to SQL data types.
• Hibernate framework saves you a lot of time for developing
database-extensive applications as it does all the database hard work
so you have more time to focus on implementing business logic.
Imagine you can perform CRUD operations and much more without
writing any SQL statements.
What is Hibernate?
• the Hibernate Query Language (HQL) allows you to write object-
oriented queries for advanced operations.
• Hibernate is an implementation of Java Persistence API (JPA) so your
code has high interoperability with other Java EE applications.
What is Hibernate?
• the Hibernate Query Language (HQL) allows you to write object-
oriented queries for advanced operations.
• Hibernate is an implementation of Java Persistence API (JPA) so your
code has high interoperability with other Java EE applications.
What is ORM?
• ORM stands for Object-Relational Mapping (ORM) is a programming
technique for converting data between relational databases and
object oriented programming languages such as Java, C#, etc.
What is ORM?
create table EMPLOYEE (
id INT NOT NULL auto_increment,
first_name VARCHAR(20) default NULL,
last_name VARCHAR(20) default NULL,
salary INT default NULL,
PRIMARY KEY (id)
);
and ORM class
Emp e1=new Emp("Shyam","Rajput","shyam.rajput@gmail.com");
int x=(Integer) session.save(e1);
Emp e1=session.get(Emp.class,x);
Query query=session.createQuery("from student");
List<Student> students=query.list();
Hibernate CRUD Apps
• Create objects
• Read objects
• Update objects
• Delete objects
Advantages
Advantages

1 Let’s business code access objects rather than DB tables.

2 Hides details of SQL queries from OO logic.


3 Based on JDBC 'under the hood.'
4 No need to deal with the database implementation.

5 Entities based on business concepts rather than database


structure.
6 Transaction management and automatic key generation.

7 Fast development of application.


Java ORM Frameworks
• Enterprise JavaBeans Entity Beans
• Java Data Objects
• Castor
• TopLink
• Spring DAO
• Hibernate
Hibernate
• Hibernate ORM (Hibernate in short) is an object-relational
mapping tool for the Javaprogramming language. It provides
a framework for mapping an object-oriented domain model to
a relational database.

• Hibernate maps Java classes to database tables and from Java data
types to SQL data types
Hibernate Archietcutre

• JDK
• Database Server
• Hibernate JAR File and JDBC
Download
• Download the latest version of Hibernate
from http://www.hibernate.org/downloads

• Following is the list of the packages/libraries required by Hibernate


and you should install them before starting with Hibernate.
Our Steps
• Create Eclipse Project
• Download Hibernate Files
• Download MySQL JDBC Driver
• Add JAR files to Eclipse Project
• Now extract and Copy paste
Copy and Paste Here
Now mySQL connector
Now right click on project
Now Create new Package
Test Connection
• Click to open file
Steps
• Add Hibernate Configuration File
• Annotate Java Class
• Develop Java Code to perform database Operations
Copy This file from the folder
ORM
Two Options for Mapping

• Option 1: XML config file(legacy)


• Option 2: JAva Annotations(modern,preferred)

Das könnte Ihnen auch gefallen