I wonder whether anyone has come accross this problem before: I’m querying a mysql database via hibernate, when I create a Criteria object and add a ‘like’ clause to it everything works fine, eg:
Criteria criteria = session.createCriteria(npd.hibernate.Plant.class);
criteria.add( Expression.like(“genus”, plantForm.getGenus() +”%”));
list = criteria.list();
However, when I add a second ‘like’ clause both of them are ignored and I get the entire table back, eg:
Criteria criteria = session.createCriteria(npd.hibernate.Plant.class);
criteria.add( Expression.like(“genus”, plantForm.getGenus() +”%”));
criteria.add( Expression.like(“species”, plantForm.getSpecies() +”%”));
list = criteria.list();
The sql that’s generated is:
Hibernate: select this.id as id0_, this.active as active0_, this.genus as genus0_, this.species as species0_ from plant this where this.genus like ? and this.species like ?
..where the parameters are ‘a%’ and ‘b%’. The generated sql works just fine when run straight against the database. I’m totally at a loss as to where the problem is. Any assistance would be greatly appreciated.