This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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: 62801
203
  • Mark post as helpful
  • send pies
  • 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.
 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!