aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate : Could not execute query -- Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate : Could not execute query -- Exception" Watch "Hibernate : Could not execute query -- Exception" New topic
Author

Hibernate : Could not execute query -- Exception

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
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.


SCJP 1.4 SCJD
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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

Joined: Apr 01, 2009
Posts: 650
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

Joined: Jan 25, 2006
Posts: 239
Thank you all.
After I changed the from to .
That method can run successfully.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate : Could not execute query -- Exception