JPQL错误 [英] Error with JPQL

查看:112
本文介绍了JPQL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JPA和JPQL有问题.我有下一个查询:

I have a problem with JPA and JPQL. I have the next query:

String query="SELECT c from Cliente c";
Query quer=em.createQuery("Select c from Cliente c");
List<Cliente> lista= quer.getResultList();

执行该操作时,出现以下错误:

When I execute that, i hace the following error :

[java]线程主"中的异常java.lang.NoClassDefFoundError:antlr/RecognitionException [java]位于org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:59) [java]位于org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:103) [java]位于org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80) [java]位于org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [java] org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [java] org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) [java]位于org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735) [java] org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) [java]位于test.TestCliente.main(TestCliente.java:35) [java]原因:java.lang.ClassNotFoundException:antlr.RecognitionException [java] at java.net.URLClassLoader $ 1.run(URLClassLoader.java:366) [java] at java.net.URLClassLoader $ 1.run(URLClassLoader.java:355) [java],位于java.security.AccessController.doPrivileged(本机方法) [java]位于java.net.URLClassLoader.findClass(URLClassLoader.java:354) [java]位于java.lang.ClassLoader.loadClass(ClassLoader.java:423) [java]位于sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) [java]位于java.lang.ClassLoader.loadClass(ClassLoader.java:356) [java] ...另外9个

[java] Exception in thread "main" java.lang.NoClassDefFoundError: antlr/RecognitionException [java] at org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:59) [java] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:103) [java] at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80) [java] at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168) [java] at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221) [java] at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199) [java] at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735) [java] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) [java] at test.TestCliente.main(TestCliente.java:35) [java] Caused by: java.lang.ClassNotFoundException: antlr.RecognitionException [java] at java.net.URLClassLoader$1.run(URLClassLoader.java:366) [java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355) [java] at java.security.AccessController.doPrivileged(Native Method) [java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354) [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:423) [java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:356) [java] ... 9 more

CLiente类是可访问的,但我无法进行查询.

The class CLiente is accesible, but I cant make a query.

有人知道为什么吗?

在类路径中是类RecognitionException,可以导入他,所以我不知道出了什么问题.

In the classpath is the class RecognitionException and I can import him, so i dont know what is the problem.

推荐答案

您很可能使用了错误的antlr jar.我只是在我的一个使用休眠模式的Maven项目中进行了查找.

You most likely have the wrong antlr jar. I just looked it up in one of my maven projects that uses hibernate.

我有hibernate-core-4.1.8和antlr-2.7.7,它在那里工作.

I have hibernate-core-4.1.8 and antlr-2.7.7, it works there.

您始终可以在特定版本的hibernate-core的pom.xml中查找正确的版本.

You can always lookup the correct version in the pom.xml of hibernate-core of your specific version.

请确保将两个位置固定为正确的版本号 例如.对于4.1.8:

Be sure to fix the two places for the correct version number e.G. for 4.1.8:

http://repo1.maven.org/maven2/org/hibernate/hibernate-core/4.1.8.Final/hibernate-core-4.1.8.Final.pom
                                                           ^ ^ ^                      ^ ^ ^

或浏览至版本概述: http://repo1.maven .org/maven2/org/hibernate/hibernate-core/并选择您的版本,然后选择"pom.xml".在dependencies部分中查找antlr条目,然后就可以了.

or browse to the version overview: http://repo1.maven.org/maven2/org/hibernate/hibernate-core/ and select your version, then 'pom.xml'. Look in the dependencies section for the antlr entry and there you go.

这篇关于JPQL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆