Spring Architecture – An Introduction

Spring Architecture – An Introduction:
Spring is a lightweight framework used to build java applications. In this article let us see the Spring Architecture in detail.

architecture

There are seven modules in Spring,

  • Core
  • ORM
  • DAO
  • AOP
  • MVC
  • Application Context
  • Web Context

CORE:
This forms the base of Spring framework. All the other modules are built over Core module. This module contains Bean factory container which forms the basis to implement Dependency Injection.

DAO:
Data Access Object – This module provides a standard way for data access. (Hibernate, JDBC etc..).  Normally in an application to access the database we need to opening connection, perform the operation and close the connection. But in Spring DAO, We can overcome this issue’s because Spring takes care of opening and closing of database connections and all we have to do write code to perform the operations.

ORM:
Object Relational Mapping – This helps us to integrate Spring framework with other Frameworks such as Hibernate, JDO etc.

AOP:
Aspect Oriented Programming – Helps in implementing aspects within our application. Aspect Oriented Programming helps us to separate application logic from system level services.

MVC:
Model View Controller – This module helps us to separate application logic from the view.

Application Context:
This module is built over Core Module. Application Context has all the concepts of Bean factory and in addition to those concepts application context has internalization of Messages, life cycle events and validation

Web Context:
Web Context is a part of web application which includes MVC module.

Read More

Hibernate Interview Questions – Part 1

Hibernate Interview Questions – Part 1
(Hibernate Interview Questions Part 2)

What is Hibernate?
It is a open source and light weight ORM  tool
It is used to store, retrieve and manipulate the database.


What is ORM?
ORM stands for Object/Relational Mapping
Matching the object with data in database


What is Impedance Mismatch?
Object oriented applications use relational database to store and retrieve the data.
Object oriented application is in class while relational database represent the data in tabular format.
We can access class using Object but in order to access the data in relational database we need to use query.
The differences between Object Oriented and Relational Database is known as Impedance Mismatch



What are the types of Impedance Mismatch?
Granularity:
Difference between number of classes mapped with database tables
Subtypes:
Differences in relationship among the classes and tables in database
Identity:
Refers to how the objects are differentiated in application and relational database.(In database object is differentiated with Primary key, as in Object model it is distinguished based on object identity and equality)
Association:
Difference in linking classes in application and linking of tables in database.(One entity can have reference to another entity, but in relational database linking is done with help of foreign keys)

We use ORM to overcome impedance mismatch by mapping data representations of Object model having data types to relational data model with SQL data types


What are the Features of Hibernate?
ORM
– matches object model and relational database
Supports inheritance, polymorphism, abstraction and collections framework
Transparent Persistence – changes made in object are automatically detected and updated in database
Database Independent
Provides HQL similar to SQL


Explain Hibernate Architecture:
Consists of,
Configuration class:
 An instance of this class is created once during the initialization. This is used for reading and parsing the properties required to connect database and application
SessionFactory Interface:
Created using an object of Configuration class. This is used to create and open session to communicate with database. This is configured separately for each database being connected
Session Interface:
 Created with SessionFactory object and is used to communicate with database
Transaction Interface:
Created with help of Session Object and is used to perform logical unit of work from database
Query Interface:
Used to create query to perform operations in database
Criteria Interface:
Used to create query to perform database operations with conditions


How to create Hibernate Session?
configure():
 This method loads hibernate.cfg.xml file and initializes the object of Configuration class with configuration properties specified in xml file
getProperties():
 Used to fetch the properties  for configuration that are configured in configure()
applySettings():
Uses serviceRegistryBuilder to apply settings fetched from getProperties().
buildSessionFactory():
 Uses configuration object from Configure() and instantiate new SessionFactory Object. (ServiceRegistry object as parameter)

(Hibernate Interview Questions Part 2)


Read More