ID を持っている学生の学校を取得するために使用される単純なCriteria
ものがあります。学生ではなく学校だけが必要です。次のような単純なコーディングがあります。
public School loadSchool(Integer studentID)
{
final Session session = getHibernateTemplate().getSessionFactory().openSession();
final Criteria like = session.createCriteria(Student.class)
.add(idEq(studentID))
.setFetchMode("School",FetchMode.JOIN);
final School retValue = ((Student)like.uniqueResult()).getSchool();
session.close();
return retValue;
}
ご覧のとおり、 も取得します。私の質問Student and the School
だけが必要です。School
1)。setProjections()
[DB から取得] を抽出できる以外の方法があります。これは、多くのフィールドがあり、すべてのフィールドを一覧表示するのが面倒で、次のようなパフォーマンスに影響するためではありSchool fields
ませんStudent fields
setProjection
setProjectionOnlyPropertiesForClass(School.class)
.
2)。任意の回避策があります。
どうもありがとう。