Hibernate 4 tutorials for beginners

The Hibernate 4 tutorials for beginners will walk you through series of step by step tutorials and from beginning to advanced. As you know, Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool. ORM is a methodology where objects in Java Applications are persisted transparently in the relational database tables.

Hibernate Architecture
The below diagram show you a high-level view of the application architecture used Hibernate.

Hibernate 4 tutorials for beginners
Source from JBoss.org

As you see in the diagram, Hibernate stays between your application and database. Hibernate provides the persistence for application via set of API’s, performing transformation transparently between java objects and database.

How does Hiberate works

Speaking generally, when your application startups, Hibernate reads configuration parameters from file hibernate.cfg.xml or hibernate.properties. These files contain database connection and mapping information, based that information Hibernate initializes Configuration object, SessionFactory object.

Hibernate initializes instances of entity classes that configured in mapping file. Each class is mapped to the database table via XML configuration or Annotations. Each instance is mapped to a row in the relevant table, Fields are columns and references are foreign-key columns.

Each class is mapped to table; Each instance is mapped to a row in the relevant table; Fields are columns, and references are foreign-key columns. Each instance that is stored in database will have an identifier, it is usually a simple auto-increment int.

Here, the key to the whole business is the mapping: Which field and which class matches which column and which table.

When an instance is not persisted in database yet, it is called transient object or it is in transient state. In short, an object is in transient state if it just has been instantiated and there is no reference of it in the database.

To persist an object, Hiberate get a Session object from SessionFactory which manage a physical database connection. Then, Hibernate starts a transaction to save that object int database, and now this object is called persistent object or it is in persistent object. In short, an object is in the persistent state if it has some reference in the database

Next step, Hibernate commits the transaction and closes session. Here, this object is called detached object or it is in detached state. In short, an object that has been persistent and is no longer in the session scope. Hibernate will not detect any changes made to this object. But this object still contains data so that it can be connected to the new session again to make it persistent again.

Now, I list of Hibernate 4 tutorials for beginners following the order that help you learn Hibernate from beginning to advanced tutorials.

Hibernate 4 tutorials for beginners:
Hibernate Hello World Example in Eclipse (Xml configuration)
Hibernate 4 example Hello World using xml configuration in Eclipse.

Hibernate Annotations Example in Eclipse
Hibernate 4 Annotations Example using Java configuration in Eclipse

Difference between get and load method in Hibernate
This is one of the most popular interview questions. It helps you understand deeper about Hibernate.

Difference between save and persist method in Hibernate
This is one of the most popular interview questions. It helps you understand deeper about Hibernate.

Difference between save and saveOrUpdate in Hibernate
This is one of the most popular interview questions. It helps you understand deeper about Hibernate.

Hibernate 4 tutorials with Bidirectional and Unidirectional associations:

Hibernate One-To-One Mapping Example using Annotation (Shared Primary Key)
Hibernate 4 example uses One-To-One Unidirectional Shared primary key mapping, two tables share the same primary key.

Hibernate One-To-One Mapping Example using Foreign key Annotation
Hibernate 4 example uses One-To-One Unidirectional Foreign Key association mapping using annotation based configuration.

Hibernate Many to One Mapping Annotation Example
Hibernate 4 example uses Many-To-One Unidirectional mapping using annotation based configuration.

Hibernate Many to One Bidirectional Mapping Annotation Example
Hibernate 4 example uses Many-To-One Bidirectional mapping using annotation based configuration.

Hibernate Many-To-Many Unidirectional Mapping Example
Hibernate 4 example uses Hibernate Many-To-Many Unidirectional mapping using annotation based configuration.

Hibernate Many-To-Many Bidirectional Mapping Example
Hibernate 4 example uses Hibernate Many-To-Many Bidirectional mapping using annotation based configuration.

Hibernate cache levels tutorials:
Hibernate First Level Cache Example
This tutorial will help you understand about First Level Cache mechanism of Hibernate

Hibernate Second Level Cache Example – Ehcache configuration example
This tutorial helps you understand about Second Level Cache mechanism via ehcache configuration.

Hibernate Query Cache Example
This tutorial shows you how Query Cache works with Second level cache

Hibernate performance tuning tutorials:
Constructor based HQL – Select new object in Hibernate
Hibernate performance tuning with Constructor based HQL

We will continue to update other Hibernate 4 tutorials for beginners as soon as possible.

Leave a Comment

*

Please share it if you found this useful
Hide Buttons