I have the following table structures:
Task - (has one) - mandate
Mandate - (has many) - mandateContacts (of type Contact)
Contact
Of course, Hibernate created a table called mandate_contact which links those contacts to a mandate.
I have to write a criteria starting from the Task table which should sound like:
Fetch a task if one of the contacts associated to a mandate has a specific name.
So far, I have created aliases like:
createAlias('mandate', 'mnd', CriteriaSpecification.LEFT_JOIN)
This is quite simple using the criteria builder:
The above assumes that your
Taskdomain class which has amandateproperty of theMandatedomain class type. TheMandatehas a collection calledmandateContactswhich is a collection of theContactdomain class and that theContactdomain class has a property callednamewhich you want to match against.I recommend you read the documentation I linked to to understand createCriteria and how it functions.