Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

6. hibernate


Published on

JSP (Java Server Pages) Lecture # 6
If you want to learn the jsp's Framework (Hibernate) then it is definatly the best lecture to learn in 15 mins

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

6. hibernate

  2. 2. What is Hibernate? Hibernate is an object-relational mapping (ORM)library for the Java language, providing a frameworkfor mapping an object-oriented domain model to atraditional relational database.Source: WikiPedia
  3. 3. Hibernate Life Cycle
  4. 4. Steps In Creating Hibernate Application1. Create Database(preferably MySQL)2. Create Web Project and select Hibernate option in Framework.
  5. 5. Database Connection
  6. 6. 3. Once Project is created, explore “hibernate.cfg.xml” file, located insource package, for configuration. (This file contains details of DB connection)4. Add property that enables thread and sql within application. To add property double click “hibernate.cfg.xml” file and go to design view. Expand Configuration property and Miscellaneous Property.
  7. 7. 5. Add “hibernate.show_sql” property by setting vlaue “true”.6. Now expand ‘Miscellaneous Properties’ node and add“hibernate.current_session_context_class” with value „thread‟.7. Add another property “hibernate.query.factory_class” with value setto “org.hibernate.hql.classic.ClassicQueryTransactionFactory”.8. Creating the “” Helper File (For session factory).
  8. 8. Generating Hibernate Mapping Files andPOJOs Classes9. First Create Hibernate Reverse Engineering File For Hibernate Mapping Files and POJOs from a Database wizard you need„hibernate.reveng.xml‟ file. The Hibernate Mapping Files and POJOs from a Database wizard requires„hibernate.reveng.xml‟ and „hibernate.cfg.xml‟.10. Right-click the Source Packages node in the Projects window andchoose New > Other to open the New File wizard.11. Select Hibernate Reverse Engineering Wizard in the Hibernatecategory.
  9. 9.  Select Tables you want to load in reverse engineering file.
  10. 10. Caution: In Netbeans edit hibernate.cfg.xml file and changefollowing:
  11. 11. Creating the Hibernate Mapping Files andPOJOs12. Select Hibernate Mapping Files and POJOs from a Database in theHibernate category. Click Next.13. Ensure that the „hibernate.cfg.xml‟ and „hibernate.reveng.xml‟ filesare selected in the drop down lists. (This will make java files for each table present in DB)
  12. 12. Creating the Helper Class15. will be used to perform Hibernate queries on the database.16. Create new java file and append file with following java code.
  13. 13. Adding helper functions in helper file
  14. 14. Reference