Hi,
My database is mysql4.1.1, when I query it with just one 'like' expression, it works fine, eg:
Criteria criteria = session.createCriteria(npd.hibernate.Plant.class);
criteria.add( Expression.like("genus", plantForm.getGenus() +"%" ));
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 ? order by this.genus asc, this.species asc
(where the parameter is 'a%')
But when I add another 'like' expression, the criteria is ignored altogether and I get the entire database 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 ? order by this.genus asc, this.species asc
(where the parameters are 'a%' and 'a%')
The generated sql works just fine against the database.
Thank you, any assistance would be greatly appreciated.
|