java - Spring MVC Hibernate Error creating bean with name 'sessionFactory' -
i trying integrate hibernate spring. until dont introduce hibernate code & libraries, works fine. here code,
welcome-servlet.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd" xmlns:mvc="http://www.springframework.org/schema/mvc"> <context:annotation-config /> <context:component-scan base-package="java4s" /> <mvc:annotation-driven /> <bean id="employeeservice" class="java4s.service.employeeserviceimpl" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="configlocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource" p:driverclassname="oracle.jdbc.pool.oracledatasource" p:url="jdbc:oracle:thin:@localhost:1521:ims" p:username="username" p:password="password" /> </beans>
libraries
antlr-2.7.6 c3p0-0.9.1 cglib-2.2 com.springsource.org.aopalliance-1.0.0 commons-collections-3.1 dom4j-1.6.1 ejb3-persistence hibernate-commons-annotations-3.2.0.final hibernate3 hibernate-entitymanager-3.6.10.final hibernate-tools-3.6.0.cr1 javassist-3.12.0.ga jboss-logging-3.3.0.final jstl-api jstl-impl jta-1.1 log4j-1.2.11 ojdbc6 org-apache-commons-logging oscache-2.1 slf4j-api-1.6.1 slf4j-simple-1.6.1 spring-aop-3.2.3.release spring-aspects-3.2.3.release spring-beans-3.2.3.release spring-build-src-3.2.3.release spring-context-3.2.3.release spring-context-support-3.2.3.release spring-core-3.2.3.release spring-expression-3.2.3.release spring-instrument-3.2.3.release spring-instrument-tomcat-3.2.3.release spring-jdbc-3.2.3.release spring-jms-3.2.3.release spring-orm-3.2.3.release spring-oxm-3.2.3.release spring-struts-3.2.3.release spring-test-3.2.3.release spring-tx-3.2.3.release spring-web-3.2.3.release spring-webmvc-3.2.3.release spring-webmvc-portlet-3.2.3.release
error
org.springframework.beans.factory.beancreationexception: error creating bean name 'sessionfactory' defined in servletcontext resource [/web-inf/welcome-servlet.xml]: invocation of init method failed; nested exception org.hibernate.mappingexception: annotationconfiguration instance required use <mapping class="java4s.model.employee"/> org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1482) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458) org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:608) org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) org.springframework.web.servlet.frameworkservlet.configureandrefreshwebapplicationcontext(frameworkservlet.java:651) org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:599) org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:665) org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:518) org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:459) org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:136) javax.servlet.genericservlet.init(genericservlet.java:160) org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1023) org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:310) java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) java.lang.thread.run(thread.java:744) root cause org.hibernate.mappingexception: annotationconfiguration instance required use <mapping class="java4s.model.employee"/> org.hibernate.cfg.configuration.parsemappingelement(configuration.java:1597) org.hibernate.cfg.configuration.parsesessionfactory(configuration.java:1552) org.hibernate.cfg.configuration.doconfigure(configuration.java:1531) org.hibernate.cfg.configuration.doconfigure(configuration.java:1505) org.hibernate.cfg.configuration.configure(configuration.java:1440) org.springframework.orm.hibernate3.localsessionfactorybean.buildsessionfactory(localsessionfactorybean.java:645) org.springframework.orm.hibernate3.abstractsessionfactorybean.afterpropertiesset(abstractsessionfactorybean.java:188) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1541) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1479) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521) org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458) org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:295) org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:292) org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:608) org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:932) org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:479) org.springframework.web.servlet.frameworkservlet.configureandrefreshwebapplicationcontext(frameworkservlet.java:651) org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:599) org.springframework.web.servlet.frameworkservlet.createwebapplicationcontext(frameworkservlet.java:665) org.springframework.web.servlet.frameworkservlet.initwebapplicationcontext(frameworkservlet.java:518) org.springframework.web.servlet.frameworkservlet.initservletbean(frameworkservlet.java:459) org.springframework.web.servlet.httpservletbean.init(httpservletbean.java:136) javax.servlet.genericservlet.init(genericservlet.java:160) org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1023) org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:310) java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) java.lang.thread.run(thread.java:744)
i know getting error because of hibernate code i.e.
<bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="configlocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
how can make work?
try with
<bean id="sessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean">
instead of
<bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean">
Comments
Post a Comment