Nearby lessons

7 of 19

Hibernate - Configuration Approaches

📌 What You Will Learn
  • 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

Example02
Loading editor…

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

Example03
Loading editor…

ANS

Example04
Loading editor…

ANS

Example05
Loading editor…

ANS

Example06
Loading editor…

ANS

Employee.hbm.xml

Example07
Loading editor…

ANS

ClientApp.java

Example08
Loading editor…

ANS

Example09
Loading editor…

ANS

Example10
Loading editor…

ANS

Example11
Loading editor…

ANS

Example12
Loading editor…

ANS

Example13
Loading editor…

ANS

Example14
Loading editor…

ANS

Example on without configuration file and without mapping file in Programmatic approach:

Employee.java

Example15
Loading editor…

ANS

Example16
Loading editor…

ANS

Example17
Loading editor…

ANS

Example18
Loading editor…

ANS

Example19
Loading editor…

ANS

ClientApp.java

Example20
Loading editor…

ANS

Example21
Loading editor…

ANS

Example22
Loading editor…

ANS

Example23
Loading editor…

ANS

Example24
Loading editor…

ANS

Example25
Loading editor…

ANS

Example26
Loading editor…

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.

Example27
Loading editor…

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

Example29
Loading editor…
📝 Key Takeaways
  • Key ideas of Hibernate - Configuration Approaches explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.