• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Hibernate : Could not execute query -- Exception  RSS feed

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a method like below:

When the program run that method, there is a exception of:

Hibernate: select from
net.sf.hibernate.exception.SQLGrammarException: Could not execute query

.
There is a table of customer, and the session.save(customer), update, and session.delete(customer) can successfully be executed.
If you have an idea, please guide me. Thanks.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't look like a legal query. A query would look like:

This would select all customer records, as there is no WHERE clause, etc.
 
ranger
Posts: 17344
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because in HQL/JPAQL you do not use table names and field names. You use Java objects and Java object attributes. So you class name is not customer it is Customer. And in the other reply, because you use HQL you do not need a SELECT portion. In JPAQL you would need the SELECT portion and you would need to alias Customer.

Mark
 
Mark Spritzler
ranger
Posts: 17344
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One other quick question. I noticed you were using the old way of doing Hibernate with creating transactions and Java 1.4 syntax.

Are you using Java 5 or higher? And are you using Hibernate 3.x? If so, use generics from Java 5 so the list() would return a List<Customer> instead of just List.

I talk more about a better approach if you are using 3.x after your reply.

Mark
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark Spritzler wrote:That's because in HQL/JPAQL you do not use table names and field names. You use Java objects and Java object attributes. So you class name is not customer it is Customer. And in the other reply, because you use HQL you do not need a SELECT portion. In JPAQL you would need the SELECT portion and you would need to alias Customer.

Mark



Sorry. I'm reading EJB3 in Action, which is dealing with JPQL (I assume that is the same as JPAQL as you call it).

I didn't realize there was yet another QL
 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.
After I changed the from to .
That method can run successfully.
 
Mark Spritzler
ranger
Posts: 17344
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark E Hansen wrote:

Mark Spritzler wrote:That's because in HQL/JPAQL you do not use table names and field names. You use Java objects and Java object attributes. So you class name is not customer it is Customer. And in the other reply, because you use HQL you do not need a SELECT portion. In JPAQL you would need the SELECT portion and you would need to alias Customer.

Mark



Sorry. I'm reading EJB3 in Action, which is dealing with JPQL (I assume that is the same as JPAQL as you call it).

I didn't realize there was yet another QL



Yes, I called in JAPQL as in the JPA Query Language. But in his code he is not using JPA, he has Hibernate Session instead of EnitytManager.

Mark
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!