2009-11-02 4 views
0

최대 절전 모드의 학생을 위해 다음과 같은 클래스 설정이 있습니다. 클래스 학생은 일련의 점수 객체를 포함합니다. 각 점수 객체에는 점수, 학생 ID 및 gradeEvent 객체가 포함됩니다. 등급 이벤트 객체에는 날짜, 설명 등이 포함됩니다. 학생을 가져오고 여기에 연결된 점수 객체와 가져온 각 Score 객체와 연결된 gradeEvent 객체를로드하려고합니다. 다음 HQL은 세션이 닫혀있어 후 그래서 그것을 액세스 할 수 HQL을 통해 세 번째 수준의 클래스를 가져오고로드하기

"from Student student left join fetch student.scores where student.studentId=1" 

가 어떻게 질의 시간에 gradeEvent 객체를로드 할 수 있습니다 gradeEvent

나를 연관된 점수 개체의 필드와 학생 개체에 액세스 수락 할 수 있습니다? 내 매핑 파일의 관련 섹션을 아래에 넣었습니다.

학생

<set name="scores" inverse="true" lazy="true" table="score" fetch="select"> 
<key> 
<column name="student_id" not-null="true" /> 
</key> 
<one-to-many class="gradebook.model.Score" /> 
</set> 

<many-to-one name="student" class="gradebook.model.Student" update="false" insert="false" fetch="select"> 
<column name="student_id" not-null="true" /> 
</many-to-one> 
<many-to-one name="gradeEvent" class="gradebook.model.GradeEvent" update="false" insert="false" fetch="select"> 
<column name="event_id" not-null="true" /> 
</many-to-one> 

gradeEvent이

<set name="scores" inverse="false" lazy="true" table="score" fetch="select"> 
<key> 
<column name="event_id" not-null="true" /> 
</key> 
<one-to-many class="gradebook.model.Score" /> 
</set> 

답변

1

당신은 점수했던 정확히 같은 방식으로 액세스 할 수 있습니다 점수; 컬렉션에 별칭을 지정하면 다시 참조 할 수 있습니다.

from Student student 
left join fetch student.scores score 
left join fetch score.gradeEvent 
where student.studentId=1 
관련 문제