我有一个关于休眠的急切和延迟加载的问题。我有以下设置:
public Person {
int prsnId;
Set<Preferences> preferences;
Set<ContactDetails> contactDetails;
//constructor
//getters & setters
}
休眠映射:
<hibernate-mapping>
<class name="be.bene.cris2.protocol.Person" table="BENE_CUST_PERSON" dynamic-update="true" dynamic-insert="true">
<id name="prsnId" type="int">
<column name="PRSN_ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">CUST_PROR_SEQ</param>
</generator>
</id>
<set access="field" name="preferences" table="PRSN_PREF" inverse="true">
<key column="PRSN_ID" not-null="true"/>
<one-to-many class="Preferences" not-found="ignore"/>
</set>
<set access="field" name="contactDetails" table="CNTCT_DETAILS" inverse="true">
<key column="PRSN_ID" not-null="true"/>
<one-to-many class="ContactDetails" not-found="ignore"/>
</set>
</class>
</hibernate-mapping>
现在,当我执行以下查询时,我想知道是否可以在运行时决定例如应该预先加载首选项,但应该延迟获取 contactDetails,或者有时根本不获取。
Criteria criteria = session.createCriteria(Person.class);
criteria.setFirstResult(startRow)
.setMaxResults(pageSize)
.add(Restrictions.eq("prsnId", id))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
;
List<Person> personList = criteria.list();
提前致谢。