3

I am getting the following error when I try to run a query using EntityManager:

Exception in thread "main" java.lang.reflect.InvocationTargetException
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8

What could be causing this?

Code:

public static void main(String [] args) {

        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("myClass");

        EntityManager em = entityManagerFactory.createEntityManager();

        List<String> results= em.createQuery(
                "SELECT * FROM myClass ")
                .setMaxResults(10)
                .getResultList();

}
java123999
  • 6,974
  • 36
  • 77
  • 121

1 Answers1

8

You cannot use * operator in HQL. You can try like below:

List<String> results= em.createQuery(
                "SELECT myclass FROM myClass ")
                .setMaxResults(10)
                .getResultList();

Hope this helps!

Ravi Ranjan
  • 740
  • 2
  • 10
  • 31