Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EQNA6DJ9VgCtW6zhCE8Xud
98 lines
2.3 KiB
Java
98 lines
2.3 KiB
Java
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);
|
|
}
|
|
}
|