Criteria crit = session.createCriteria(Order.class)
.add(example);
if (order.getCustomer() != null) {
Customer customer = order.getCustomer();
crit = crit.createCriteria("customer");
if (customer.getCustomerNr() != null) {
crit.add(Restrictions.eq("customerNr",
customer.getCustomerNr()));
}
if (customer.getFirstName() != null) {
crit.add(Restrictions.ilike("firstName",
customer.getFirstName()));
}
if (customer.getLastName() != null) {
crit.add(Restrictions.ilike("lastName",
customer.getLastName()));
}
}
if (order.getConstructionType() != null) {
crit.add(Restrictions.eq("constructionType",
order.getConstructionType()));