• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
Sheriff
Posts: 17314
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
Sheriff
Posts: 17314
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
Sheriff
Posts: 17314
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!