스프링 데이터, JPA를 사용 중이며 manyToOne
관계를 사용하여 데이터를 가져올 수 없습니다.스프링 데이터를 사용하여 manyToOne을 사용하여 데이터를 가져올 수 없습니다. JPA
나는 2 개의 실체 Employee
, EmployeeTransferRequest
을 가지고 있습니다.
@Entity
@Table(name = "employee_detail")
public class EmployeeDetail{
private Employee employee;
private Long empId;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "emp_id", insertable = false, nullable = false,updatable = false)
public Employee getEmployee() {
return _student;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
@Column(name = "emp_id", updatable = false)
public Long getEmpId() {
return empId;
}
public void setEmpId(Long empId) {
this.empId = empId;
}
}
@Entity
@Table(name = "employee")
class Employee
{
@Override
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = " emp_id")
public Long getEmpId() {
return _id;
// Other Fields of Employee class ..
}
}
public interface EmployeeTransferRequestRepository extends JpaRepository<EmployeeTransferRequest, UUID>, QueryDslPredicateExecutor<EmployeeTransferRequest>
{
default EmployeeTransferRequest findOneUUID transferRequestId) {
return findOne(employeeTransferRequest.id.eq(transferRequestId);
}
}
나는 Employee
기업 측에서 EmployeeTransferRequest
을지도하지 않았다. 유일한 uni-directional
은 EmployeeTransferRequest
입니다.
내가 findOne
를 호출하고
EmployeeTransferRequest
에서 모든 정보를 얻을 수 있어요,하지만
null
을 받고,
Employee
정보를 받고.
도와 주시겠습니까?
FetchType을 LAZY에서 EAGER로 변경하려고 했습니까? –
@ melli-182, 예, 저는 EAGER로 LAZY를 바꾸어 시도했지만 작동하지 않았습니다. – Venky
실제 코드를 게시하십시오. 이 코드는 컴파일되지 않습니다 : capital class, missing parens. getter에 주석을 달아주기 때문에 최대 절전 모드에서는 값을 채우기 위해 setter를 사용해야하지만 아무 것도 없기 때문에 작동하지 않을 수 있습니다. 하지만 ... 이것은 실제로 사용하는 코드가 아닙니다 ... –