Learnitweb

Category: Hibernate tutorial

  • Hibernate N+1 Problem

    Introduction The N+1 problem in Hibernate is a common performance issue that occurs when an application executes excessive database queries due to improper handling of relationships. This can severely degrade application performance, especially when dealing with large datasets. Understanding the N+1 Problem What is the N+1 Problem? The N+1 problem occurs when Hibernate retrieves a…

  • One-to-One Mapping in Hibernate

    Introduction One-to-One mapping in Hibernate represents a relationship where each record in one table corresponds to exactly one record in another table. This is commonly used when entities have exclusive relationships, such as User and Address. In this tutorial, we will: Project Setup Ensure you have the following dependencies in your pom.xml: Database Configuration Configure…

  • 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.…