Add Hibernate 7 batches 2-6 and batch 7: mapping styles, JPA annotations, natural IDs, @Immutable, stored procedures, in-memory test databases, JNDI mocking, proxies, associations, temporal mapping, named queries, HQL, Criteria API, EntityManager bootstrapping, Ehcache 3 L2 cache configuration, HikariCP connection pooling, and Hibernate Validator CDI integration (Hibernate 7.4.5.Final + Spring Boot 4.1.1 + JDK 25)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EQNA6DJ9VgCtW6zhCE8Xud
This commit is contained in:
2026-09-20 04:56:34 +00:00
committed by Claude
co-authored by Claude Sonnet 5
commit 4292f1cd54
283 changed files with 21259 additions and 0 deletions
@@ -0,0 +1,49 @@
package com.ankurm.hibernatedemo.query;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
/**
* Shared by the HQL chapter (15) and the Criteria API chapter (16) &mdash; both posts use the
* same Employee/Department pair in their examples, so one real mapping backs both rather than
* two near-duplicates.
*
* <p>Named {@code QueryDept} (entity name, via {@code @Entity(name = ...)}), not {@code
* Department}, because chapter 06's {@code naturalid.Department} already claims that entity
* name in this same persistence unit -- Hibernate requires distinct entity names project-wide,
* not just distinct class names.
*
* <p>Docs: docs/15-hql-queries.md, docs/16-criteria-queries.md.
*/
@Entity(name = "QueryDept")
public class Department {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
protected Department() {
// JPA
}
public Department(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Department{id=%s, name=%s}".formatted(id, name);
}
}
@@ -0,0 +1,97 @@
package com.ankurm.hibernatedemo.query;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import java.time.LocalDate;
/**
* Shared by the HQL chapter (15) and the Criteria API chapter (16).
*
* <p>Docs: docs/15-hql-queries.md, docs/16-criteria-queries.md.
*
* <p>{@code status} and {@code hireDate} exist specifically for the bulk-update/bulk-delete
* scenarios both chapters cover ({@code UPDATE ... WHERE lastLogin/hireDate < :cutoff}-shaped
* queries), and {@code department} is LAZY so the fetch-join chapter has a real N+1 to avoid
* rather than an asserted one.
*/
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
private Double salary;
private String status;
private LocalDate hireDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "department_id")
private Department department;
protected Employee() {
// JPA
}
public Employee(String firstName, String lastName, Double salary, String status, LocalDate hireDate, Department department) {
this.firstName = firstName;
this.lastName = lastName;
this.salary = salary;
this.status = status;
this.hireDate = hireDate;
this.department = department;
}
public Long getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public LocalDate getHireDate() {
return hireDate;
}
public Department getDepartment() {
return department;
}
@Override
public String toString() {
return "Employee{id=%s, firstName=%s, lastName=%s, salary=%s, status=%s}"
.formatted(id, firstName, lastName, salary, status);
}
}