Newsletter:

(Tutorial) Hibernate Java Persistence

Tutorial : Hibernate Java Persistence

Introduction to Hibernate Java
Hibernate is a widely used open source software that provides object-relational mapping (ORM) solution for the Java language. It provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. It eases the work of application developer by generating the database code so developer does not have to handle relational data persistence-related programming tasks.

Java Persistence with Hibernate
Java provides JDBC to work with databases but the problem is that it requires developer to write SQL code for the database
exposes the data model to the application code. A better approach is to use Hibernate which takes care of SQL coding itself. You have to do mapping to let framework know which application filed maps to which database field.

Hibernate Java Persistence
Hibernate provides persistence for Java objects. It uses reflections and has support for over 30 different database drivers. So you can use hibernate for persistence with all popular databases. It has a query language to access objects and this query language provides high performance and low resource contention.

Hibernate uses runtime reflection to determine persistent properties of classes. It uses a mapping property to generate database schema which is used and provide persistence.

Hibernate - Concurrency
Java Hibernate has two types of concurrenies, optimistic concurrency and pessimistic concurrency.

Hibernate ensures optimistic concurrency by directly using JDBC connections and JTA resources without adding any additional locking behavior. Hibernate does not lock objects in memory. The application can expect the behavior as defined by the isolation level of the database transactions.
Thanks to the Session, which is also a transaction-scoped cache, Hibernate provides repeatable reads for lookup by identifier and entity queries (not reporting queries that return scalar values).

Hibernate ensures pessimistic concurrency by using an API for pessimistic locking of rows, using the SELECT FOR UPDATE syntax.

Hibernate – Optimistic Cocurrency
The only approach that is consistent with high concurrency and high scalability is optimistic concurrency control with versioning. Version checking uses version numbers, or timestamps, to detect conflicting updates (and to prevent lost updates)...

[Read More..]

Courtesy:- Java-forums.org