Hibernate
The
process of storing data to permanent place and retrieving data from
permanent place is called as persistence and such data is called as
persistent data.
Add,
remove, read and modify operations on persistence data are called as persistence operations and the logic used for it is called as persistence logic.
The
place where data will be stored permanently is called as persistence store. As the data became permanent we can use it any moment through
programming.
Ex:
Flat files, Database software etc...
Flat
files: are normal files where data can stored and maintained
by OS(Operating System). For example, .txt, .xls
Limitations
of flat files:
- No security for data.
- Files may deleted by mistake.
- Do not support query language like sql.
- Dealing with huge amount of data is quite complex.
Object
Database Software:
The
database software that is capable of storing java objects or any
other objects directly in table columns as values is called object
database software.
Limitations
of Object Database Software:
- It stores and object containing multiple values in a column of a table. This is violation of normalization rule I which says don't store multiple values in a single column.
- Generating reports from Object oriented database software is complex.
Drawbacks
of implementing persistence logic by using JDBC:
- JDBC uses SQL queries to implement persistence logic. These SQL queries are database dependent so JDBC based persistence logic becomes database dependent.
- As JDBC based persistence logic is database dependent, change of database software becomes complex and disturbs persistence logic.
- Programmer is responsible to take care of exception handling and transaction management.
- When SQL select queries are executed JDBC code generates ResultSet object since ResultSet object is not a serializable object we cannot send this object over the network.
- We need to write additional code to have connection pooling.
To
overcome the above problems we can work with ORM [Object Relational
Mapping] based persistence logic.
Object
Relational Mapping:
- The process of mapping java class with database table, java class member variables with database table columns and making java objects representing table rows having synchronization between them is called as OR Mapping.
- In OR Mapping every table row will be represented by a separate java object.
- Synchronization between java objects and table row means any modification in table row reflects in java object and vice verse.
- To take care of Synchronization and OR Mapping based persistence logic development we need ORM software.
Advantages
of ORM:
- We can perform insert, delete, select and update operations on the table using java objects that are representing table rows.
- Here database queries are not reuired. Hence OR Mapping based persistence logic becomes database independent persistence logic.
- Change of database software from a running project becomes easy because there is no need of modifying persistence logic in OR Mapping.
- As programmer developed java class objects are representing table rows we can make these objects as serializable by making the class to implement java.io.Serializable interface.
List
of ORM software's:
- Hibernate [Soft Tree]
- iBatis [Apache]
- Toplink [Oracle Corp]
- Entity beans of EJB [Sun Microsystems]
- JPA(Java Persistence Api) [Sun Microsystems]
- OJB [Apache]
- JDO [Adobe]
Note:
List has declared based on usage wide.
Hibernate:
Hibernate is an open source, light weight ORM tool to develop DB
independent persistence logic in java based enterprise application.
MVC [Model
– View – Control]
M –
Model – Business Logic + Persistence Logic
V
- View – Persistence Logic
C
- Controller – Integration Logic
we
cannot use hibernate to develop persistence and business logic. It
means to develop only persistence logic of an application.
API
dependent: means classes and interface used in the application
development must extend or implement one of the predefined classes or
interfaces.
Ex:
Our Servlet application is API dependent because of it must implement
or extends from predefined GenericServelt or HttpServlet class.
Hibernate
Application: are light weight because classes and interfaces
are not API dependent . There is no need of container/web/application
servers to manage hibernate applications.
POJO
classes: The classes that are not API dependent are called
POJO [Plain Old Java Object] classes. A POJO class is a class which
will contains the private variables with getter and setter methods.
In the below PojoEx.java file is the example of POJO class. This will
helps you to map with database table.
POJI [Plaing Old Java Interface]: POJI is an interface which should not extend any predefined interfaces which belongs to API specific.
PojoEx.java
package com.javatbrains; import java.io.Serializable; public class PojoEx implements Serializable { private int id; private int name; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getName() { return name; } public void setName(int name) { this.name = name; } } |
POJI [Plaing Old Java Interface]: POJI is an interface which should not extend any predefined interfaces which belongs to API specific.
package com.javatbrains; import java.io.Serializable; public interface PojiEx { } interface iter1 extends PojiEx{} interface inter2 extends Runnable{} interface inter3 extends Serializable{} |
The
above interfaces are example of POJI because they have not extended
from any of the API specific interfaces.
Hibernate
API: Hibernate API contains multiple API. Mainly used API's
are mentioned in the below.
- Core API: Used by programmers to develop basic hibernate application.
- Extension API: Programmer uses this API to add additional functionality/services to the application.
- Miscellaneous API: This API provides built in tools related to hibernate.
- Internal Implementation: Hibernate software and engine comes in the form of internal implementation API.
Comments
Post a Comment