Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [Texo/Hibernate] createQuery() returns 0 results but raw SQL works
[Texo/Hibernate] createQuery() returns 0 results but raw SQL works [message #698609] |
Tue, 19 July 2011 19:54 |
Mike Cooper Messages: 60 Registered: February 2011 |
Member |
|
|
I have a strange situation where I'm doing a lookup of a value using createQuery() which is returning 0 results, yet if I execute the raw SQL provided by Hibernate sql_show=true it works fine.
Here's the code:
Query query = session.createQuery("FROM RegistrationCode WHERE Code='" + name + "'");
List<?> regCodes = query.list();
if (regCodes == null) {
log.debug(m, "No regCode with Code=<%s> found", name);
return null;
}
// Should only be 1 match if success
log.debug(m, "Found %d matches for code=<%s>", regCodes.size(), name);
In this code the name variable is set to something like "G8KA-38D4-C2KH". The debug output looks like:
INFO: 2011-07-19 11:23:24,526 DEBUG [vortex.reg.RegCodeManagerPersist] getByCode: Get regCode with Code=<G8KA-38D4-C2KH>
INFO: Hibernate: select registrati0_.dbID as dbID14_, registrati0_.dbVersion as dbVersion14_, registrati0_.code as code14_, registrati0_.created as created14_, registrati0_.creator_dbID as creator17_14_, registrati0_.description as descript5_14_, registrati0_.devType as devType14_, registrati0_.devVendorModel as devVendo7_14_, registrati0_.devVendorName as devVendo8_14_, registrati0_.mobileRadioType as mobileRa9_14_, registrati0_.name as name14_, registrati0_.osName as osName14_, registrati0_.phoneNumber_dbID as phoneNu18_14_, registrati0_.status as status14_, registrati0_.updated as updated14_, registrati0_.useCountMax as useCoun14_14_, registrati0_.validStart as validStart14_, registrati0_.validUntil as validUntil14_ from RegistrationCode registrati0_ where Code='G8KA-38D4-C2KH'
INFO: 2011-07-19 11:23:24,532 DEBUG [vortex.reg.RegCodeManagerPersist] getByCode: Found 0 matches for code=<G8KA-38D4-C2KH>
If I take the SQL in the "INFO: Hibernate: select ..." line and execute directly on the database (mysql) it finds the given entry just fine.
The database is mysql 5.0. Using the latest version of Texo and Hibernate as of 7/19/2011.
Any suggestions?
|
|
|
Re: [Texo/Hibernate] createQuery() returns 0 results but raw SQL works [message #698623 is a reply to message #698609] |
Tue, 19 July 2011 20:21 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Mike,
I have really no idea, other than that maybe the code around your code changes the database or does other things. For
the rest I can not see why it would be different.
gr. Martin
On 07/19/2011 09:54 PM, Mike Cooper wrote:
> I have a strange situation where I'm doing a lookup of a value using createQuery() which is returning 0 results, yet if
> I execute the raw SQL provided by Hibernate sql_show=true it works fine.
>
> Here's the code:
>
> Query query = session.createQuery("FROM RegistrationCode WHERE Code='" + name + "'");
> List<?> regCodes = query.list();
> if (regCodes == null) {
> log.debug(m, "No regCode with Code=<%s> found", name);
> return null;
> }
> // Should only be 1 match if success
> log.debug(m, "Found %d matches for code=<%s>", regCodes.size(), name);
>
>
> In this code the name variable is set to something like "G8KA-38D4-C2KH". The debug output looks like:
>
>
> INFO: 2011-07-19 11:23:24,526 DEBUG [vortex.reg.RegCodeManagerPersist] getByCode: Get regCode with Code=<G8KA-38D4-C2KH>
> INFO: Hibernate: select registrati0_.dbID as dbID14_, registrati0_.dbVersion as dbVersion14_, registrati0_.code as
> code14_, registrati0_.created as created14_, registrati0_.creator_dbID as creator17_14_, registrati0_.description as
> descript5_14_, registrati0_.devType as devType14_, registrati0_.devVendorModel as devVendo7_14_,
> registrati0_.devVendorName as devVendo8_14_, registrati0_.mobileRadioType as mobileRa9_14_, registrati0_.name as
> name14_, registrati0_.osName as osName14_, registrati0_.phoneNumber_dbID as phoneNu18_14_, registrati0_.status as
> status14_, registrati0_.updated as updated14_, registrati0_.useCountMax as useCoun14_14_, registrati0_.validStart as
> validStart14_, registrati0_.validUntil as validUntil14_ from RegistrationCode registrati0_ where Code='G8KA-38D4-C2KH'
> INFO: 2011-07-19 11:23:24,532 DEBUG [vortex.reg.RegCodeManagerPersist] getByCode: Found 0 matches for code=<G8KA-38D4-C2KH>
>
>
> If I take the SQL in the "INFO: Hibernate: select ..." line and execute directly on the database (mysql) it finds the
> given entry just fine.
>
> The database is mysql 5.0. Using the latest version of Texo and Hibernate as of 7/19/2011.
>
> Any suggestions?
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
| |
Goto Forum:
Current Time: Thu Sep 19 22:38:42 GMT 2024
Powered by FUDForum. Page generated in 0.03439 seconds
|