introduction to hibernate framework
TRANSCRIPT
![Page 1: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/1.jpg)
Introduction to Hibernate Framework
www.collaborationtech.co.inBengaluru INDIA
Presentation By Ramananda M.S Rao
![Page 2: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/2.jpg)
ContentContentIntroductionObject PersistenceHibernate ConfigurationPersistent ClassesAnnotationsPersistence Life CycleComponents and ModelMapping and AssociationEntity Inheritance with Hibernate Intermediate ConceptsHibernate Query and CriteriaFetching StrategiesHibernate objectsListenersProjectAbout Us
www.collaborationtech.co.in
![Page 3: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/4.jpg)
Hibernate Framework Architecture
www.collaborationtech.co.in
![Page 5: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/5.jpg)
ExampleStudentEntity.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
![Page 6: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/6.jpg)
Examplepublic 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
![Page 7: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/7.jpg)
Examplepackage 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
![Page 8: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/8.jpg)
ExampleStudentEntity 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
![Page 9: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/9.jpg)
Examplehibernate.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
![Page 10: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/10.jpg)
Follow us on SocialFacebook: https://www.facebook.com/collaborationtechnologies/Twitter : https://twitter.com/collaboration09Google Plus : https://plus.google.com/100704494006819853579LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545Instagram : https://instagram.com/collaborationtechnologiesYouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUgSkype : facebook:ramananda.rao.7WhatsApp : +91 9886272445
www.collaborationtech.co.in
THANK YOU
![Page 11: Introduction to Hibernate Framework](https://reader035.vdocuments.site/reader035/viewer/2022062310/58a29aed1a28ab36508b7655/html5/thumbnails/11.jpg)
About Us