Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4H5ph3J7k2MJnRuVH
40 lines
877 B
Java
40 lines
877 B
Java
package com.ankurm.onetomany;
|
|
|
|
import jakarta.persistence.CascadeType;
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.OneToMany;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/** The one-to-many side with no fetch attribute: JPA's default for @OneToMany is LAZY. */
|
|
@Entity
|
|
public class EagerDepartment {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
private String name;
|
|
|
|
@OneToMany(mappedBy = "department", cascade = CascadeType.ALL)
|
|
private List<EagerEmployee> employees = new ArrayList<>();
|
|
|
|
protected EagerDepartment() {
|
|
}
|
|
|
|
public EagerDepartment(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public List<EagerEmployee> getEmployees() {
|
|
return employees;
|
|
}
|
|
}
|