HIBERNATE / NOTES</>↗Hibernate15 Jun 2025
In Hibernate (or JPA in general), the @Embeddable and @Embedded annotations are used to help manage object-relational mapping for complex types (value types) within entities. These annotations allow you to define reusable and nested objects that don’t require their own database table but are saved as part of the owning entity. Here’s how to use […]
HIBERNATE / NOTES</>↗Hibernate14 Jun 2025
In Hibernate (and JPA), fetching strategies (lazy and eager) control how related entities are loaded from the database. Understanding how to use these strategies effectively is essential for optimizing application performance. Here’s what you need to know: 1. Eager Fetching Definition: When a relationship is marked as eager, Hibernate retrieves the related entity or collection […]
HIBERNATE / NOTES</>↗Hibernate13 Jun 2025
To integrate Hibernate’s second-level cache with EHCache, follow these steps: Step 1: Add Dependencies Ensure that you have the required dependencies in your project: For Maven: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>6.4.4.Final</version> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> <version>3.10.8</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifac...
HIBERNATE / NOTES</>↗Hibernate13 Jun 2025
In Hibernate, you can use the @OneToMany and @ManyToOne annotations to map a one-to-many relationship. Below is a step-by-step explanation with an example: Explanation: One-To-Many Side: Use the @OneToMany annotation on the field representing the collection in the parent entity. Typically, this will be a List, Set, or other collection type. Many-To-One Side: Use the […]
HIBERNATE / NOTES</>↗Hibernate12 Jun 2025
To handle database connections in a Hibernate standalone application, you need to set up Hibernate configuration carefully and ensure the correct management of the Hibernate SessionFactory and Session objects. Below are the general steps to achieve this: Steps to Handle Database Connections in Hibernate Standalone Application 1. Add Required Hibernate Dependencies Ensure you include the […]
HIBERNATE / NOTES</>↗Hibernate12 Jun 2025
Defining a primary key using the @Id and @GeneratedValue annotations in Hibernate (or JPA) is straightforward and commonly used to automate primary key generation for database entities. Here’s a guide: Steps: Use @Id annotation: Marks a field in your entity class as the primary key. Use @GeneratedValue annotation: Specifies that the primary key values should […]