Hello,
I created a table with the script belove in a Derby database and created Entity Class for that.
create table "BAHADIR"."User"
(
"id" NUMERIC(5) not null primary key,
"name" VARCHAR(25),
"email" VARCHAR(100),
"password" VARCHAR(25),
"role" VARCHAR(25)
)
In my controller class there's a method like that:
public int getItemCount() {
EntityManager em = getEntityManager();
try{
int count = ((Long) em.createQuery("select count(o) from User as o").getSingleResult()).intValue();
return count;
} finally {
em.close();
}
}
When this method is called I get that exception stack:
HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
root cause
javax.el.ELException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
root cause
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
root cause
org.hibernate.exception.SQLGrammarException: could not execute query
root cause
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "User" at line 1, column 42.
root cause
org.apache.derby.client.am.SqlException: Syntax error: Encountered "User" at line 1, column 42.
note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.
Sun Java System Application Server 9.1
What does these mean? The IDE created the access method automatically, so it can not be wrong. So where's the error?
Thanks.