Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
INTRODUCTION• Hibernate is an Object-relational mapping(ORM) tool.• ORM is a programming method for mappingthe objects to the relational model whereentities/classes are mapped to tables,instances are mapped to rows and attributesof instances are mapped to columns of table.
What does Hibernate do??• Hibernate provides a solution to map databasetables to a class.• It copies one row of the database data to aclass.• In the other direction it supports to saveobjects to the database.• Saving data to a storage is called persistence.And the copying of tables to objects and viceversa is called object relational mapping.
PERSISTENT CLASS• Java classes whose objects or instances will bestored in database tables are called persistentclasses 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 USINGHIBERNATE• 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 thepersistent object7. Run the application
DOWNLOAD JAR FILES• we can download jars related to hibernate at• http://sourceforge.net/projects/hibernate/files/hibernate3• From the above URL choose hibernate 3.2.2-ga.zip, as we are in initial stage this version will bebetter.• Unzip it, and now you can find some jar files inthe lib folder right..?, actually we doesn’t requireall the jar files, out of them just select thefollowing 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