0

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 fieldssetProjection

setProjectionOnlyPropertiesForClass(School.class).

2)。任意の回避策があります。

どうもありがとう。

4

1 に答える 1