I am sorry... I cannot get this to work. I will give you my needs as it is a bit more complicated than my example...
I have a Customer. This customer has a collection of the entity Contract and a collection of CustomerData (more information on the customer). Each contract as a collection of the data for the contract (ContractData). The contract data in turn has a collection of the Entity Product which it represent.
What I want:
I want the customer for who I have the primary key. Then I want to eager fetch the customer data and I want to join the contracts on this customer. I also want to join the contract data on each contract (if the property historicDate is null). I finally want to join the products on the contract data if the property isDeleted is null or false.
This is my code which do not work :(
Code:
Criteria criteria = session().createCriteria(Customer.class) //
.add(Restrictions.eq("id", customerId)) //
.setFetchMode("contracts", FetchMode.JOIN) //
.setFetchMode("customerData", FetchMode.SELECT) //
.createAlias("contracts", "c") //
.setFetchMode("c.contractData", FetchMode.JOIN) //
.createAlias("c.contractData", "cd") //
.add(Restrictions.isNull("cd.historicDate")) //
.setFetchMode("cd.product", FetchMode.JOIN) //
.createAlias("cd.product", "p") //
.add(Restrictions.not(Restrictions.eq("p.isDeleted", true)));
This criteria returns null and no customer.... Anyone?