Nearby lessons
7 of 19Hibernate - Configuration Approaches
- Understand Hibernate - Configuration Approaches
- See working code examples
- Learn from common mistakes and Q&A
Learn Hibernate - Configuration Approaches step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.
ANS
Yes, it is possible to run Hibernate applications without using configuration file.
In Hibernate Applications, we are able to provide configuration details in the following two
approaches.
ANS
a) By using properties file
b) By Using XML file
ANS
In Programmatic approach, to provide configuration details, first we have to create Configuration
class object then we have to set all hibernate properties to Configuration class object explicitly by
using the following method.
public void setProperty(String prop_Name, String prop_Val)
To add mapping file name and location to Configuration file we have to use the following method.
public void addResource(String mapping_File_Name)
Note: If we are using annotations in place of mapping file then we have to use the following
method to add annotated class.
public void addAnnotatedClass(Class class)
Example on without configuration File and with mapping file in Programmatic Approach:
Employee.java
ANS
ANS
ANS
ANS
Employee.hbm.xml
ANS
ClientApp.java
ANS
ANS
ANS
ANS
ANS
ANS
ANS
Example on without configuration file and without mapping file in Programmatic approach:
Employee.java
ANS
ANS
ANS
ANS
ANS
ClientApp.java
ANS
ANS
ANS
ANS
ANS
ANS
ANS
In Programatic approach, if we want to change configuration details like connection properties or
database properties,.... then we have to perform modifications in JAVA code, if we perform
modifications in JAVA code then we must recompile the java application , it is not suggestible in
enterprise applications. To overcome the problem we have to use Declarative approach.
2) Declarative approach
In Declarative approach, we will provide all configuration details in either properties file or in XML
file then we will send configuration details to Hibernate application.
There are two ways to provide configuration details to Hibernate Applications in Declarative
Approach.
2) Declarative approach
- Key ideas of Hibernate - Configuration Approaches explained simply
- Ready-to-use code examples
- Exam-style questions at the end