JPQL createQuery throws illegalArgumentException
Question
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.
Solution
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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow