DataAccessException cannot be resolved. It is indirectly referenced from required .class files
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
Related videos on Youtube
odysseas
Updated on June 04, 2022Comments
-
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 over 6 yearsHow did you import the project into eclipse?
-
odysseas over 6 yearsI didn't import it. I created it from a Maven Archetype (web mvc) and followed the tutorial.
-
twinklehawk over 6 yearsIf you expand the Maven Dependencies folder under your project, do you see the spring-tx jar?
-
odysseas over 6 yearsYes, version 5.0.2.RELEASE
-
robot_alien over 6 yearstry 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 over 6 yearsYou can try cleaning the project by selecting the project then clicking Project->Clean at the top. What tutorial are you following?
-
odysseas over 6 years@twinklehawk a tutorial about spring on udemy called "Spring framework in easy steps". I tried twice but nothing...
-
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 over 6 yearsDid 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 over 6 yearsI did it from the command line.
-
robot_alien over 6 yearsOk, 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 over 6 yearsWell, 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 about 6 yearsWelcome 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?