facebook

Two ‘like’ criteria fails

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #219695 Reply

    davidkiwi
    Member

    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.

    #219719 Reply

    Riyad Kalla
    Member

    Moving to OT> Soft Dev

    Also david I’d highly suggest you to cross-post this to hibernate forums… the hib guys might have a better idea about this faster than we do.

    #219730 Reply

    davidkiwi
    Member

    thanks, I’ll try doing that again, got no reply first time, guess no one has come accross this particular situation before.

    #219733 Reply

    Riyad Kalla
    Member

    It certainly seems odd that the SQL is legit… it executes fine, but just not from Hibernate…. =/

    #220119 Reply

    davidkiwi
    Member

    In case anyone is interested, I tried replacing the MySql database with hsqldb, the queries now work perfectly.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Two ‘like’ criteria fails

You must be logged in to post in the forum log in