DB에 간단한 일대 다 관계가 있습니다. 여기에 해당하는 클래스는 다음과 같습니다 count
업데이트 유지하기 위해최대 절전 모드를 사용하여 테이블의 '많은'항목 수를 업데이트합니다.
class Department
{
int deptId;
int count; //This corresponds to the total number of Employees in a department
List<Employee> employees; //An employee belongs to only one department
}
class Employee
{
int employeeId;
Department dept;
}
, 나는 각 CUD
작업에 count
을 설정하고있다. Department에 직원을 추가/삭제할 때마다 count
을 자동으로 업데이트 할 수 있습니까? (주석/제한 또는 기타)
좋은 답변입니다. 왜 당신은 오직 stackoverflow에서만 진정합니까? : P –
각 부서 액세스에 모든 직원 행을로드하지 않으려는 것입니다. FetchType은 LAZY입니다. 그러나 각 Dept에서 읽은 요약 (직원 수)을 표시해야합니다. –
그런 다음 "Extra Lazy"페칭 시작일 (http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#performance-fetch)을 살펴보아야합니다. 주석을 사용하는 경우 @LazyCollection (LazyCollectionOption.EXTRA) – overmeulen