Hi
I am creating a search query consisting of multiple associations. I need OR for all fields, I am able to define OR on fields with in an association. But I would also like to define OR on all associations also. Below is the code I am using currently:
Code:
Criteria customerCriteria = this.getSession().createCriteria(Customer.class);
Criteria contactsCriteria = customerCriteria.createCriteria("contacts");
Criteria ordersCriteria = customerCriteria.createCriteria("orders");
customerCriteria
.add(Restrictions.disjunction()
.add(Restrictions.like("email", "tony123@yahoo.com"))
.add(Restrictions.like("pk", new IntegerPk("customer", "2"))));
contactsCriteria
.add(Restrictions.disjunction()
.add(Restrictions.like("email", "tony456@gmail.com"))
.add(Restrictions.like("phone1", "7079845675"))
.add(Restrictions.like("person.firstName", "Test First Name").ignoreCase())
.add(Restrictions.like("person.lastName", "Test Last Name").ignoreCase())
.add(Restrictions.like("address.postalCode", "94952", MatchMode.ANYWHERE)));
ordersCriteria
.add(Restrictions.like("pk", new IntegerPk("order", "1")));
List<ICustomer> customerList = customerCriteria.list();
User can enter "email" defined in Customer Criteria, "First Name" defined in Contacts Criteria and "Order PK" defined in Order Criteria. What I need is OR between all associations.
Apart from OR, It would be very helpful if some one can give "Query By Example" alternative of this.
Thanks in advance