【问题标题】:Hibernate and antlr.RecognitionException not found未找到休眠和 antlr.RecognitionException
【发布时间】:2017-09-26 18:15:28
【问题描述】:

我想学习休眠。我找到了一些教程,但我在启动项目时遇到了一个问题。这是我的pom:

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.2.1.jre8</version>

    </dependency>


    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.5.Final</version>
    </dependency>

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>

</dependencies>

这是我的课:

public static void main(String[] args) {

    Session session = HibernateUtilWapro.getSessionFactory().openSession();

    Query q = session.createQuery("From Employee ");

    List<Employee> resultList = q.list();
    System.out.println("num of employess:" + resultList.size());
    for (Artykul next : resultList) {
        System.out.println("next employee: " + next);
    }
}

我在 Eclipse Oxygen 中将它作为 Java 应用程序运行,但出现以下错误:

线程“main”中的异常 java.lang.NoClassDefFoundError: antlr/RecognitionException 在 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:57) 在 org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:124) 在 org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:88) 在 org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190) 在 org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) 在 org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) 在 org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)

它需要什么依赖?非常感谢您的帮助

【问题讨论】:

  • 我也有同样的问题。

标签: hibernate noclassdeffounderror


【解决方案1】:

您可以尝试添加以下依赖项。它解决了我的问题。

<dependency>
 <groupId>org.antlr</groupId>
 <artifactId>antlr-complete</artifactId>
 <version>3.5.2</version>
</dependency>   

【讨论】:

    【解决方案2】:

    在我的情况下,我缺少添加 hibernate-core 的依赖项:

    添加

    <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>5.4.30.Final</version>
    </dependency>
    

    然后刷新依赖并重启App。

    【讨论】: