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();
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With