Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QuerySyntaxException: Unexpected token * [duplicate]

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();

}
like image 790
java123999 Avatar asked Mar 27 '26 04:03

java123999


1 Answers

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!

like image 51
Ravi Ranjan Avatar answered Mar 28 '26 16:03

Ravi Ranjan