DataAccessException cannot be resolved. It is indirectly referenced from required .class files

16,652

Solution 1

Download jar from this link

import into your project, it will resolve.

Your HibernateTemplate class is importing org.springframework.dao.DataAccessException class which is not present in your classpath.

Solution 2

Add in pom for Maven project

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>

or add jar spring-tx

Share:
16,652

Related videos on Youtube

odysseas
Author by

odysseas

Updated on June 04, 2022

Comments

  • odysseas
    odysseas almost 2 years

    I'm usign Spring ORM with Hibernate, and when I write the command

    hibernateTemplate.save(entityInstance);
    

    (entityInstance is obviously an instance of a User entity)

    I get this error:

    The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files
    

    Even though i followed a (working) tutorial step-by-step (and code-by-code) it doesn't work. This is my pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.dsystems</groupId>
    <artifactId>newtokenmanager</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>newtokenmanager Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.5.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>5.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
        </dependency>
    
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.2</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    

    Eclipse also suggests me as 'quick fix' to configure build path from the menu, but I don't know exactly what to do. As some people suggested for similar issues here on SO, I tried by removing and reloading both JRE System Library and Maven dependencies, but didn't work.

    • twinklehawk
      twinklehawk over 6 years
      How did you import the project into eclipse?
    • odysseas
      odysseas over 6 years
      I didn't import it. I created it from a Maven Archetype (web mvc) and followed the tutorial.
    • twinklehawk
      twinklehawk over 6 years
      If you expand the Maven Dependencies folder under your project, do you see the spring-tx jar?
    • odysseas
      odysseas over 6 years
      Yes, version 5.0.2.RELEASE
    • robot_alien
      robot_alien over 6 years
      try doing a mvn clean install on your project, as it looks like you are trying to refer to one of the spring jars which aren't in your project build path. Also do a Project->Clean & set enable Build Automatically in eclipse.
    • twinklehawk
      twinklehawk over 6 years
      You can try cleaning the project by selecting the project then clicking Project->Clean at the top. What tutorial are you following?
    • odysseas
      odysseas over 6 years
      @twinklehawk a tutorial about spring on udemy called "Spring framework in easy steps". I tried twice but nothing...
    • odysseas
      odysseas over 6 years
      @robot_alien The mvn clean install command says "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?" even though I am using JDK (tried also to use JRE instead but it's the same). As I said to twinklehawk I did Project > Clean twice. Also, "Build automatically" was enabled since the beginning.
    • twinklehawk
      twinklehawk over 6 years
      Did you do the mvn clean install from the command line or from inside eclipse? If you did it inside eclipse, does it work from the command line?
    • odysseas
      odysseas over 6 years
      I did it from the command line.
    • robot_alien
      robot_alien over 6 years
      Ok, in your eclipse, go to Window-> Preferences-> Java -> Installed JREs-> check your installed JRE. You should have an entry with a JDK there. If no, please add one... Once that's done, do Project rt click Maven -> Update Project. Let me know if it worked for you...!
    • odysseas
      odysseas over 6 years
      Well, jdk was already checked... So I tried by doing that procedure with Jre and then changing it again with jdk... Nothing happened. I also tried by downgrading hibernate to 5.1.x because i noticed that 5.2.x is still in development, but still no change. I was wondering, why does eclipse suggest me as 'quick fix' to change the build path? I don't get it.
  • anothernode
    anothernode about 6 years
    Welcome to Stack Overflow! Maybe it's just me, but I can't figure out how this answers the question. Could you maybe explain it a little bit?