Introduction to Hibernate Framework

RaveendraRoodagi 1,512 views 11 slides Feb 09, 2017
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

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 o...


Slide Content

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