Suppose I have a many to one relation between Task and User, there also a one to one relation between User and UserRegistration

In Task there is a collection like bellow:

<many-to-one name="createBy" column="CRE_BY" not-null="true"/>

In User there is a collection like bellow:

<many-to-one name="userRegInfo" column="USER_REG_ID" not-null="true" cascade="all" unique="true" />

Now if I want to access information from TaskInfo may need to join UserInfo with TaskInfo and as a result may need to join UserRegInfo and UserInfo to get specific data.

This can be done following way:


DetachedCriteria dCriteria =DetachedCriteria.forClass(TaskInfo.class);
- - - - - - - - -  - - - - - - - - -  - - - - - - - - - dCriteria.setFetchMode("createBy",FetchMode.JOIN).

setFetchMode("createBy.userRegInfo", FetchMode.JOIN);
- - - - - - - - -  - - - - - - - - -  - - - - - - - - - - -