getting sql exception when using EJB 3.0 with Java Persistence API

Hi,

On my PC when I run the sample applications in Java EE tutorial I don't get any errors. But, when I try to run my own code, then I get the SQL exception. I paste the exception stacktrace below.

The exception says that the column is not present. But, the column is actually present. The named query I used is:

@NamedQuery(name = "Book.findAll", query = "SELECT b FROM Books b");

Could any one please help on this?

========================================================

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DatabaseException

Internal Exception: org.apache.derby.client.am.SqlException: Column 'BOOKID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'BOOKID' is not a column in the target table.Error Code: -1

Call:SELECT bookid, author, price, title, inventory, catagory FROM BOOKS WHERE (catagory = CAST (? AS VARCHAR(32672) ))

bind => [Technical]

Query:ReportQuery(cart.Books)

at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)

at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)

at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)

at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.executeCall(UnitOfWorkImpl.java:1355)

at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)

at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199)

at

[1969 byte] By [pantulaa] at [2007-11-27 8:59:56]
# 1

Appears to be some schema mismatch here.

Can you check if it is hitting the right database or not? In the server.log, you can see TopLink log messages containing the database URL.

You can also try using --dropandcreatetables=true option while deploying your application. That will drop existing tables and create new ones with correct schema.

-- Sahoo

sahooa at 2007-7-12 21:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Also, the query from the log is different from the NamedQuery you mentioned, since it only selects books from a certain category. The NamedQuery selects *all* books.
mf125085a at 2007-7-12 21:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...