I am making a Struts_1.2 + Log4J2_2.0.2 + Hibernate_4.3.6 project of my own. And I made a simple DAO class and ran in local environment(simple java class that runs as local Java application), and it worked 100% fine.
Now I just called the same DAO class from a Action Controller i.e made a JSP sent the data to Action Controller then it transferred the data to DAO, server is Tomcat 7.x, and when I try to run, it says
java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
What I am unable to understand is the same code running without Tomcat(local application) but when it comes to Tomcat it is not able to find the method in the class.
I have checked the jar, it contains the file and that file has the method also(no compiler error)
I will be very grateful, if anybody can help me on this.
Maven(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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestApp</groupId>
<artifactId>TestApp</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>TestApp</name>
<description>Website</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>struts</groupId>
<artifactId>struts</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</project>
DAO(Java):
public void saveHitCountInDB(HitCount count) {
session.update(count);
session.flush();
}
POJO(Java):
@Entity
@Table(name = "hitcounter")
public class HitCount {
@Id
@Column(name = "count", unique = true, nullable = false)
private int hitCount;
//getter and setter and constructors
}
Connection(Java):
configuration = new Configuration().configure();
configuration.addAnnotatedClass(HitCount.class); //problem reported here
Note: let me know if more code is required.
Hibernate Annotation jaris wrong. It is not compatible with the jar version. So that is why it showing the "java.lang.NoSuchMethodError"pom.xml, also check pom dependency tree forhibernate-commons-annotations