MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
davidkiwi
Post subject: Two 'like' criteria fails  PostPosted: Nov 19, 2004 - 03:15 AM
Registered Member
Registered Member


Joined: Sep 25, 2004
Posts: 3

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.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Nov 19, 2004 - 02:14 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23824

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.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
davidkiwi
Post subject:   PostPosted: Nov 19, 2004 - 04:18 PM
Registered Member
Registered Member


Joined: Sep 25, 2004
Posts: 3

thanks, I'll try doing that again, got no reply first time, guess no one has come accross this particular situation before.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Nov 19, 2004 - 04:33 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23824

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

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
davidkiwi
Post subject:   PostPosted: Nov 29, 2004 - 11:19 AM
Registered Member
Registered Member


Joined: Sep 25, 2004
Posts: 3

In case anyone is interested, I tried replacing the MySql database with hsqldb, the queries now work perfectly.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits