hibernate framework

Post on 22-May-2015

286 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

HIBERNATE FRAMEWORK

Subhin P.V111subru@gmail.comwww.facebook.com/

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

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.

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.

DIAGRAMPresentation layer

Logical layer

Database

PERSISTENT CLASS

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

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();

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

CREATE JAVA PROJECT

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

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

CREATE PERSISTENT CLASS

CREATE A MAPPING FILE FOR THE PERSISTANT CLASS

CREATE A CONFIGURATION FILE

CREATE THE CLASS THAT RETRIVES OR STORES THE PERSISTANT CLASS

RUN THE APPLICATION

ADVANTAGES OF HIBERNATE

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

THANK YOU

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

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: info@baabtra.com

top related