This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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: 639
posted
0
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.
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.
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: 639
posted
0
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
posted
0
Thank you all.
After I changed the from to .
That method can run successfully.
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Hibernate : Could not execute query -- Exception