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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user