Hi all,
I am facing a different problem now. The fields in my search operation are not mandatory. The user will enter the sort criteria and the order of sorting.
In the below code companyName and companyType belong to Company POJO and city and countryCode belong to CompanyAddress POJO. Now Search is successful only when I choose atleast one values from both of the POJO and fails otherwise. The sort order is also entered by the user. How can I decide the sort order based on the users choice? The search has to be made even with a value from a single POJO?
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
session = sessionFactory.openSession();
List crit = session.createCriteria(Company.class).add(Restrictions.or(Restrictions.like("searchName",compname),Restrictions.like("companyType", companyType)))
.addOrder(Order.asc(sortCriteria))
.createCriteria("addresses", "address")
.add(Restrictions.or(Restrictions.like("address.city",city),Restrictions.like("address.countryCode",ctry )))
.list();
session.close();
System.out.println("Results----->"+crit.size());
return crit;
Where I am wrong here?. How could we change the default and operation to an or operation?
With Regards,
Amutha[/code]
|