HIBERNATE / NOTES</>↗Hibernate11 Jun 2025
To write a simple JPQL (Java Persistence Query Language) query using Hibernate, follow these steps: Example: Basic JPQL Query For example, consider we have an entity: Employee package org.kodejava.hibernate; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; @Entity @Table(name = "employee") public class Employee { @Id private Long id; private String name; private String department; private Double […]
HIBERNATE / NOTES</>↗Hibernate11 Jun 2025
Configuring Hibernate with an H2 in-memory database is quite straightforward. Below is a guide for configuring Hibernate with an H2 database in a Spring Boot or standalone Jakarta EE project. Configuration for Hibernate with H2 in-memory database 1. Add Dependencies Ensure you have the necessary dependencies in your project. For a Maven project, include the […]
HIBERNATE / NOTES</>↗Hibernate10 Jun 2025
Hibernate ORM 6 introduces several changes to its API compared to previous versions, especially in how SessionFactory and Session are used due to compliance with Jakarta EE and its updated imports (jakarta.persistence.*). Here’s a simple guide to using SessionFactory and Session in Hibernate 6: 1. Add Hibernate Dependencies Make sure to include the Hibernate 6 […]
HIBERNATE / NOTES</>↗Hibernate10 Jun 2025
To map a Java class to a database table using JPA annotations, you primarily use annotations provided by jakarta.persistence. Here is a step-by-step guide: Key annotations for mapping: @Entity Marks the class as an entity that is mapped to a table. @Table (optional) Specifies the table name in the database. If omitted, the default table […]
HIBERNATE / NOTES</>↗Hibernate09 Jun 2025
Basic CRUD operations with Hibernate 6 involve creating, reading, updating, and deleting records in a database using Hibernate ORM. Hibernate simplifies these operations through its API. Below is an explanation of each CRUD operation along with corresponding examples: 1. Create (Insert) To save a new object in the database, you use the persist() or save() […]
HIBERNATE / NOTES</>↗Hibernate09 Jun 2025
To configure hibernate.cfg.xml for a simple Hibernate application, you need to include the essential properties for Hibernate to interact with the database and map your entities. Below is an example of hibernate.cfg.xml: <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!– Database connection settings –> <property name="hib...