hibernate framework

21

Upload: baabtracom-first-coding-school-in-india

Post on 22-May-2015

286 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Hibernate Framework
Page 2: Hibernate Framework

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Page 3: Hibernate Framework

HIBERNATE FRAMEWORK

Subhin [email protected]/

subhinvelayudhantwitter.com/111subruin.linkedin.com/in/SubhinPv8129076039

Page 4: Hibernate Framework

INTRODUCTION

• Hibernate is an Object-relational mapping (ORM) tool.

• ORM is a programming method for mapping the objects to the relational model where entities/classes are mapped to tables, instances are mapped to rows and attributes of instances are mapped to columns of table.

Page 5: Hibernate Framework

What does Hibernate do??• Hibernate provides a solution to map database

tables to a class. • It copies one row of the database data to a

class. • In the other direction it supports to save

objects to the database. • Saving data to a storage is called persistence.

And the copying of tables to objects and vice versa is called object relational mapping.

Page 6: Hibernate Framework

DIAGRAMPresentation layer

Logical layer

Database

Page 7: Hibernate Framework

PERSISTENT CLASS

• Java classes whose objects or instances will be stored in database tables are called persistent classes in Hibernate.

Page 8: Hibernate Framework

Example of Persisting an Object// get a Hibernate SessionFactory for Session managementsessionFactory = new Configuration()

.configure().buildSessionFactory();

// an Event object that we want to saveLocation ku = new Location( "Kasetsart University" );ku.setAddress( "90 Pahonyotin Road; Bangkok" );Event event = new Event("Java Days");event.setLocation( ku );

Session session = sessionFactory.openSession();Transaction tx = session.beginTransaction();session.save( event );tx.commit();session.close();

Page 9: Hibernate Framework

CREATING A JAVA PROJECT USING HIBERNATE

• STEPS1. Create a Java Project2. Add jar Files for Hibernate3. Create the persistent class4. Create Mapping File for Persistence Class5. Create the configuration file6. Create the class that retrieves or stores the

persistent object7. Run the application

Page 10: Hibernate Framework

CREATE JAVA PROJECT

Page 11: Hibernate Framework

DOWNLOAD JAR FILES• we can download jars related to hibernate at• http://sourceforge.net/projects/hibernate/fil

es/hibernate3• From the above URL choose hibernate 3.2.2-

ga.zip, as we are in initial stage this version will be better.

• Unzip it, and now you can find some jar files in the lib folder right..?, actually we doesn’t require all the jar files, out of them just select the following jar files..

Page 12: Hibernate Framework

DOWNLOAD JAR FILES

• Anttr-2.7.6.jarasm.jarasm-attrs.jarcglib-2.1.3.jarcommons-collections-2.1.1.jarcommons-logging-1.0.4.jarehcash.jardom4j-1.6.1.jarhibernate3.jarjta.jarlog4j-1.2.3.jar

Page 13: Hibernate Framework

CREATE PERSISTENT CLASS

Page 14: Hibernate Framework

CREATE A MAPPING FILE FOR THE PERSISTANT CLASS

Page 15: Hibernate Framework

CREATE A CONFIGURATION FILE

Page 16: Hibernate Framework

CREATE THE CLASS THAT RETRIVES OR STORES THE PERSISTANT CLASS

Page 17: Hibernate Framework

RUN THE APPLICATION

Page 18: Hibernate Framework

ADVANTAGES OF HIBERNATE

• Opensource and lightweight• Database independent querying• Automatic table creation

Page 19: Hibernate Framework

THANK YOU

Page 20: Hibernate Framework

If this presentation helped you, please visit our page facebook.com/baabtra and like it.

Thanks in advance.

www.baabtra.com | www.massbaab.com |www.baabte.com

Page 21: Hibernate Framework

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: [email protected]