IMRAN DAUDFOUNDATION UNIVERSITYINSTITUTE OF MANAGEMENT ANDCOMPUTER SCIENCESImran DaudFUIMCSWeb EngineeringHibernate
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. 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.
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 “HibernateUtil.java” Helper File (For session factory).
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.
Select Tables you want to load in reverse engineering file.
Caution: In Netbeans edit hibernate.cfg.xml file and changefollowing:
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)
Creating the FilmHelper.java Helper Class15. will be used to perform Hibernate queries on the database.16. Create new java file and append file with following java code.