Maxim
Maxim

Reputation: 3946

java.lang.NoSuchMethodError: antlr.collections.AST.getLine() using Spring and Hibernate

I am using Spring and Hibernate and i always get this error message:

java.lang.NoSuchMethodError: antlr.collections.AST.getLine()

It happens when i make custom definitions in my repositories:

public interface UserRepository extends JpaRepository<User, Long> 
{
    @Query("select u from User u where username = ?1")
    List<User> findByUsername(String username);

    @Query("select u from User u where username = ?1 and password = ?2")
    List<User> findByUsernameAndPassword(String username, String password);
}

If i remove the 2 queries then everything works just fine.

I also added antlr as a dependency:

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

but this was unsuccessful to solve my issue.

Spring: 3.2.3 RELEASE

Hibernate:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.0.1.Final</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>1.2.0.Final</version>
    <scope>compile</scope>
</dependency> 

Upvotes: 1

Views: 5027

Answers (2)

nidalpres
nidalpres

Reputation: 3868

I'm using Spring Boot and this error happened because antlr-2.7.7 used by hibernate-core-4.3.7 was overridden by antlr-2.7.2 used by struts-core-1.3.8.

If someone has this issue in Spring Tool Suite IDE, this is what I did:

  • open project's pom.xml
  • in Dependency Hierarchy tab select antlr (2.7.2) in Resolved Dependencies list
  • in same tab in Dependency Hierarchy list right-click on antlr-2.7.7 and select "Lock Transitive Dependency Version..." and click OK.
  • save pom.xml
  • run app again

Upvotes: 2

Bart Kiers
Bart Kiers

Reputation: 170278

The class antlr.collections.AST is an ANTLR v2 class.

For the record, these are the packages of the ANTLR versions:

  • ANTLR v2, package: antlr...
  • ANTLR v3, package: org.antlr...
  • ANTLR v4, package: org.antlr.v4...

Upvotes: 0

Related Questions