Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Introduction to Hibernate Framework
www.collaborationtech.co.in
Bengaluru INDIA
Presentation By
Ramananda M.S Rao
Content
Content
Introduction
Object Persistence
Hibernate Configuration
Persistent Classes
Annotations
Persistence Life Cycle
Components and Model
Mapping and Association
Entity Inheritance with Hibernate
Intermediate Concepts
Hibernate Query and Criteria
Fetching Strategies
Hibernate objects
Listeners
Project
About Us
www.collaborationtech.co.in
Introduction
 Hibernate framework simplifies the development of java application to interact
with the database. Hibernate is an open source, lightweight, ORM (Object
Relational Mapping) tool.
 An ORM tool simplifies the data creation, data manipulation and data access. It
is a programming technique that maps the object to the data stored in the
database.
Advantages of Hibernate Framework
 Open source and Lightweight
 Fast performance
 Database Independent query: HQL (Hibernate Query Language) is the object-
oriented version of SQL.
 Automatic table creation: Hibernate framework provides the facility to create
the tables of the database automatically. So there is no need to create tables in
the database manually.
 Simplifies complex join: To fetch data form multiple tables is easy in hibernate
framework.
 Hibernate supports Query cache and provide statistics about query and database
status.
www.collaborationtech.co.in
Hibernate Framework Architecture
www.collaborationtech.co.in
Example
StudentEntity.java
package entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "student")
public class StudentEntity {
@Id
@Column(name = "ID")
private int id;
@Column(name = "NAME")
private String name;
@Column(name = "DEPARTMENT")
private String department;
@Column(name = "COLLEGE")
private String college;
public int getId() {
return id;}
www.collaborationtech.co.in
Example
public void setId(int id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getDepartment() {return department;}
public void setDepartment(String department) {this.department =
department;}
public String getCollege() {return college;}
public void setCollege(String college) {this.college = college;
}}
www.collaborationtech.co.in
Example
package util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import entity.StudentEntity;
public class HibernateUtil {
public static void main(String[] args) {
Configuration cf = new Configuration().configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
srb.applySettings(cf.getProperties());
ServiceRegistry sr = srb.build();
SessionFactory sf = cf.buildSessionFactory(sr);
Session session = sf.openSession();
www.collaborationtech.co.in
Example
StudentEntity std = new StudentEntity();
std.setId(100); // Primary Key
std.setName("Ravindra");
std.setDepartment("ECE");
std.setCollege("RNS Bangalore");
Transaction tx = session.beginTransaction();
session.save(std);
tx.commit();
System.out.println("Object saved successfully.....!!");
session.close();
sf.close();
}
}
www.collaborationtech.co.in
Example
hibernate.cfg
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume students is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost/testdb
</property>
<property name="hibernate.connection.username">
testdb
</property>
<property name="hibernate.connection.password">
root
</property>
<mapping class="entity.StudentEntity"/>
</session-factory>
</hibernate-configuration>
www.collaborationtech.co.in
Follow us on Social
Facebook: https://www.facebook.com/collaborationtechnologies/
Twitter : https://twitter.com/collaboration09
Google Plus : https://plus.google.com/100704494006819853579
LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545
Instagram : https://instagram.com/collaborationtechnologies
YouTube :
https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg
Skype : facebook:ramananda.rao.7
WhatsApp : +91 9886272445
www.collaborationtech.co.in
THANK YOU
About Us

More Related Content

Introduction to Hibernate Framework

  • 1. Introduction to Hibernate Framework www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
  • 2. Content Content Introduction Object Persistence Hibernate Configuration Persistent Classes Annotations Persistence Life Cycle Components and Model Mapping and Association Entity Inheritance with Hibernate Intermediate Concepts Hibernate Query and Criteria Fetching Strategies Hibernate objects Listeners Project About Us www.collaborationtech.co.in
  • 3. Introduction  Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.  An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps the object to the data stored in the database. Advantages of Hibernate Framework  Open source and Lightweight  Fast performance  Database Independent query: HQL (Hibernate Query Language) is the object- oriented version of SQL.  Automatic table creation: Hibernate framework provides the facility to create the tables of the database automatically. So there is no need to create tables in the database manually.  Simplifies complex join: To fetch data form multiple tables is easy in hibernate framework.  Hibernate supports Query cache and provide statistics about query and database status. www.collaborationtech.co.in
  • 5. Example StudentEntity.java package entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "student") public class StudentEntity { @Id @Column(name = "ID") private int id; @Column(name = "NAME") private String name; @Column(name = "DEPARTMENT") private String department; @Column(name = "COLLEGE") private String college; public int getId() { return id;} www.collaborationtech.co.in
  • 6. Example public void setId(int id) {this.id = id;} public String getName() {return name;} public void setName(String name) {this.name = name;} public String getDepartment() {return department;} public void setDepartment(String department) {this.department = department;} public String getCollege() {return college;} public void setCollege(String college) {this.college = college; }} www.collaborationtech.co.in
  • 7. Example package util; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import entity.StudentEntity; public class HibernateUtil { public static void main(String[] args) { Configuration cf = new Configuration().configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder(); srb.applySettings(cf.getProperties()); ServiceRegistry sr = srb.build(); SessionFactory sf = cf.buildSessionFactory(sr); Session session = sf.openSession(); www.collaborationtech.co.in
  • 8. Example StudentEntity std = new StudentEntity(); std.setId(100); // Primary Key std.setName("Ravindra"); std.setDepartment("ECE"); std.setCollege("RNS Bangalore"); Transaction tx = session.beginTransaction(); session.save(std); tx.commit(); System.out.println("Object saved successfully.....!!"); session.close(); sf.close(); } } www.collaborationtech.co.in
  • 9. Example hibernate.cfg <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <!-- Assume students is the database name --> <property name="hibernate.connection.url"> jdbc:mysql://localhost/testdb </property> <property name="hibernate.connection.username"> testdb </property> <property name="hibernate.connection.password"> root </property> <mapping class="entity.StudentEntity"/> </session-factory> </hibernate-configuration> www.collaborationtech.co.in
  • 10. Follow us on Social Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU