Category: Hibernate tutorial
-
JPA @Embedded And @Embeddable
1. Introduction In this tutorial, we’ll discuss embeddable types in JPA. An embeddable type is a composition of values. If you have a class which naturally is a part of another class then this class can be made embedded. For example, consider a class Address, which has properties Country, State and City. This Address class…
-
Hibernate Entity LifeCycle
1. Introduction In this tutorial, we’ll discuss life cycle of persistent objects in Hibernate. In a Hibernate application, there can be two types of objects: An entity object which is mapped to the table and has properties mapped to the tables. Objects which are not directly recognized by the Hibernate. Hibernate can work with both…
-
Second-level cache in Hibernate
1. Introduction In this tutorial, we’ll discuss second-level (or L2) cache in Hibernate. The persistence context is also called the first-level cache, and it’s enabled by default. But sometimes we may require to have cache data outside the context of a particular Session. The second-level cache is answer to this requirement. A second-level cache is…
-
An introduction to caching in Hibernate
1. Introduction Accessing a database is an expensive operation even if it is a simple query. The request is sent to the server over the network. The database server then compiles the SQL into a query plan. The query plan is executed and returned back to the client over the network. This complete flow may…
-
Mapping LOBs in Hibernate
1. Introduction In this tutorial, we’ll discuss mapping LOBs or database Large Objects. We’ll discuss following LOBs: Blob – Binary Large Object. It is used to store large binary data like image, audio, video etc. Clob – Character Large Object. It is used to store large character data like large text file. We’ll not discuss…
-
Mapping enums in Hibernate
1. Introduction In this tutorial, we’ll discuss mapping and persisting enums in Hibernate. An enum declaration looks like the following: Each enum constant has an ordinal which represents the sequence in the enum declaration, where the initial constant is assigned an ordinal of 0. For example, ON has ordinal value 0, OFF as 1 and…
-
Naming strategies in Hibernate
1. Introduction Hibernate as an ORM mapping tool maps objects in domain model to the relational model. To do this mapping, Hibernate has to identify which Java object to map with which relational model. ImplicitNamingStrategy and PhysicalNamingStrategy are used to identify how the mapping of names should be done. The mapping of names is done…
-
Mapping Types in Hibernate
1. Introduction Hibernate is an ORM solution. It maps object model to a relational data model (and vice-versa). Usually the object model is a Plain Old Java Object (POJO), but it is not a mandatory requirement to use Hibernate. Hibernate can easily work with other objects like java.util.Map and can map to the relational model.…
-
many-to-one association in Hibernate
1. Introduction In this quick tutorial, we’ll discuss many-to-one association in Hibernate. Associations are one of the most frequently asked questions in interview. These could be very confusing and could lead to design issues. We’ll understand many-to-one association by writing a program. The many-to-one association is one of the most common and simple associations. This…
-
Bootstrap Hibernate – Create SessionFactory
In this tutorial, we’ll create our first Hibernate application. We’ll understand how to create SessionFactory and will use it to interact with MYSQL database to get database version. 1. Create SessionFactory in Hibernate The starting point of writing a Hibernate program is to create a SessionFactory. Bootstrapping APIs are redesigned in Hibernate 5.0. The way…