• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Error org.hibernate.exception.SQLGrammarException: could not extract ResultSet

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the hql query that I am executing but receive an error that I don't really understand the cause of.

This is my code:




I get his error on the webpage when trying to execute it:



And also this console error:

 
Marshal
Posts: 79656
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please tell us what the error messge and number are, and what that number means in the MariaDB handbook.

Moving to our databases forum.
 
Saloon Keeper
Posts: 28073
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, Campbell, error message numbers are almost universally useless. Especially Oracle ones, IBM jdbc codes, and, alas MariaDB/MySQL. Although at least that last will give a half-way useful message text.

May I suggest a bit of tidying:


Mostly what I've done is make things not stretch halfway to Mars, but I also prefer to capitalize my keywords to make them more visible. And, incidentally, I would give my usual caution about using upper-case letters in table and column names, but I'll leave it to the MariaDB manual.

Having said that, it looks like there's a (yuck!) stored procedure being created/called here and a VERY complex query. Usually when a query has that many constants in it, I prefer to define a View, myself. It simplifies the actual query and you get a benefit that if your criteria change, you can re-define the View instead of changing program logic.

And what's with the "concat" in the ORDER BY. Why not simply "ORDER BY s.staff_First_Name, s.staff_Last_Name"?

The error message, incidentally, seems to be referencing a "leave2" which isn't even in this query, so I suspect we're not being told everything!
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's apparently HQL, which Hibernate will translate (and stick all those underscores etc in eg leave2_ as a table alias).
I would suggest getting Hibernate to print out what SQL it has generated.

I know next to nothing about MariaDB, so I have no idea whether there's some dialect mismatch somewhere?
 
Tim Holloway
Saloon Keeper
Posts: 28073
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:It's apparently HQL, which Hibernate will translate (and stick all those underscores etc in eg leave2_ as a table alias).
I would suggest getting Hibernate to print out what SQL it has generated.

I know next to nothing about MariaDB, so I have no idea whether there's some dialect mismatch somewhere?



Mostly MariaDB is SQL standard, although I don't know about that function-looking thing up front.

This segment:


ALMOST matches the error message:


But notice that the original HQL is "leave_Employee and the generated SQL is "Leave_Employee", likewise "staff_Code" versus "Staff_Code".

As I've said, mixing case in SQL is extremely hazardous, even when you're doing your own SQL without a translator applying its own standards. I think that may be what's wrong here.

I prefer JPA/JPQL myself. Probably just as likely to pull a stunt like that, but legacy Hibernate is best left to legacy apps.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic