I get error when i run , i used Spring MVC + Hibernate, spring 3.2 release and hibernate 4 release.
As below my code in model , servlet xml , and list of all libraries were added to path WEB-INF/lib .
1- FEP_Health_Model
package Models;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
public class FEP_Health_Model {
@Autowired
private SessionFactory factory;
public FEP_Health_Model()
{
System.out.print("Hello Spring MVC with Hibernate");
try{
configureSessionFactory();
}catch(Throwable ex){
System.err.println("Failed to create sessionFactory object." + ex); throw new
ExceptionInInitializerError(ex);
}
}
@Transactional
public void test()
{
Session session = factory.openSession();
Transaction trans = null;
try{
trans = session.beginTransaction();
/*
Some Code
*/
trans.commit();
}catch(Throwable ex){
}finally{
session.close();
}
}
private void configureSessionFactory() throws HibernateException {
AnnotationConfiguration configuration = new AnnotationConfiguration();
configuration.configure().addAnnotatedClass(FepEnergyData.class);
factory = configuration.buildSessionFactory();
}
}
2- springmvc-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<context:component-scan base-package="Controllers"></context:component-scan>
<context:component-scan base-package="Models"></context:component-scan>
<context:annotation-config />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/JSP/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url"
value="jdbc:sqlserver://127.0.0.1:1433;databaseName=AECMDMS_TEST;instanceName=SQLEXPRESS;"/>
<property name="username" value="user"/>
<property name ="password" value="123" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/META-INF/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.SQLServer2008Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:jta-transaction-manager transaction-manager="transactionManager"/>
</beans>
3- ٍlist of all libraries have been added
commons-digester3-3.2.jar
commons-io-2.4.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
hibernate-annotations-3.5.6-Final.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.5.Final.jar
hibernate-envers-4.2.5.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.1.Final.jar
log4j.jar
org.osgi.core-4.3.1.jar
org.springframework.aop-3.2.0.RELEASE.jar
org.springframework.beans-3.2.0.RELEASE.jar
org.springframework.context-3.2.0.RELEASE.jar
org.springframework.core-3.2.0.RELEASE.jar
org.springframework.jdbc-3.2.0.RELEASE.jar
org.springframework.orm-3.2.0.RELEASE.jar
org.springframework.transaction-3.2.0.RELEASE.jar
org.springframework.web.servlet-3.2.0.RELEASE.jar
org.springframework.web-3.2.0.RELEASE.jar
spring-webmvc-3.2.0.RELEASE.jar
spring-asm-3.2.0.M1.jar
spring-tx-3.2.0.RELEASE.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
slf4j-simple-1.7.5.jar
sqljdbc4.jar
xalan-2.7.1.jar
xercesImpl.jar
xml-apis.jar
Console
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory' defined in ServletContext resource [/WEB-INF/FEP_Health-servlet.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError:
org/hibernate/util/DTDEntityResolver
i hope anybody find solution for My problem