0
我有一個簡單Criteria
所使用的小同學,我有ID的學校裏,我只需要學校不是學生,我有一個簡單的編碼像Java的Hibernate的標準只返回一個實體領域
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()
,我可以提取物[從數據庫中檢索]以外的方式只有School fields
不是Student fields
,因爲對許多領域,是一種惱人的列出所有字段setProjection
和影響性能類似
setProjectionOnlyPropertiesForClass(School.class)
。 2)。有任何解決方法。
非常感謝。