2. What is Hibernate?
Hibernate is an object-relational mapping (ORM)
library for the Java language, providing a framework
for mapping an object-oriented domain model to a
traditional relational database.
Source: WikiPedia
6. 3. Once Project is created, explore “hibernate.cfg.xml” file, located in
source 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. 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 set
to “org.hibernate.hql.classic.ClassicQueryTransactionFactory”.
8. Creating the “HibernateUtil.java” Helper File (For session factory).
8. Generating Hibernate Mapping Files and
POJOs Classes
9. 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 and
choose New > Other to open the New File wizard.
11. Select Hibernate Reverse Engineering Wizard in the Hibernate
category.
9. Select Tables you want to load in reverse engineering file.
11. Creating the Hibernate Mapping Files and
POJOs
12. Select Hibernate Mapping Files and POJOs from a Database in the
Hibernate category. Click Next.
13. Ensure that the „hibernate.cfg.xml‟ and „hibernate.reveng.xml‟ files
are selected in the drop down lists. (This will make java files for each table present in DB)
12. Creating the FilmHelper.java Helper Class
15. will be used to perform Hibernate queries on the database.
16. Create new java file and append file with following java code.