views:

205

answers:

1

The following simple code throws exception:

entityManager.createQuery("SELECT c FROM Customer c");

But if I write

entityManager.createNativeQuery("SELECT c.* FROM Customer c", Customer.class)

then it works without any error. What might be wrong? I use GlassFish v2.1 with Toplink-essentials.

A: 

The JPQL query "SELECT c FROM Customer c" is valid as long as you have a class Customer defined as an Entity. That method only throws an Exception if the query is "invalid" for some reason, and any decent JPA implementation should give more information in the message of the exception if there is some problem

--Andy (DataNucleus)

DataNucleus
Thank you Andy. I have Customer class with @Entity annotation. As I said native query returns customer objects without any problem, but ordinary jpa query doesn't work.
synergetic
So I suggest that either you use the TopLink log and mailing list, or you try other JPA implementations (e.g DataNucleus) that certainly do support such syntax.
DataNucleus
Ok, Andy you were right. I used table name instead of class name. Actually my query was "SELECT c FROM customer_info c".
synergetic