Friday, 15 April 2011

xml - java Spring hibernate integration issue -



xml - java Spring hibernate integration issue -

by executing simple programme of spring hibernate integration, getting next issue..please help me resolve these issues...

nov 10, 2014 10:07:47 org.springframework.beans.factory.xml.xmlbeandefinitionreader loadbeandefinitions info: loading xml bean definitions class path resource [applicationcontext.xml] exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'd' defined in class path resource [applicationcontext.xml]: cannot resolve reference bean 'template' while setting bean property 'template'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'template' defined in class path resource [applicationcontext.xml]: cannot resolve reference bean 'mysessionfactory' while setting bean property 'sessionfactory'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'mysessionfactory' defined in class path resource [applicationcontext.xml]: initialization of bean failed; nested exception java.lang.reflect.malformedparameterizedtypeexception @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:275) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvevalueifnecessary(beandefinitionvalueresolver.java:104) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1245) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1010) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:472) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory$1.run(abstractautowirecapablebeanfactory.java:409) @ java.security.accesscontroller.doprivileged(native method) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:380) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:264) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:261) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:185) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:164) @ com.javatpoint.inserttest.main(inserttest.java:14) caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'template' defined in class path resource [applicationcontext.xml]: cannot resolve reference bean 'mysessionfactory' while setting bean property 'sessionfactory'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'mysessionfactory' defined in class path resource [applicationcontext.xml]: initialization of bean failed; nested exception java.lang.reflect.malformedparameterizedtypeexception @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:275) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvevalueifnecessary(beandefinitionvalueresolver.java:104) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1245) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1010) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:472) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory$1.run(abstractautowirecapablebeanfactory.java:409) @ java.security.accesscontroller.doprivileged(native method) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:380) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:264) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:261) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:185) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:164) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:269) ... 13 more caused by: org.springframework.beans.factory.beancreationexception: error creating bean name 'mysessionfactory' defined in class path resource [applicationcontext.xml]: initialization of bean failed; nested exception java.lang.reflect.malformedparameterizedtypeexception @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:480) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory$1.run(abstractautowirecapablebeanfactory.java:409) @ java.security.accesscontroller.doprivileged(native method) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:380) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:264) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:222) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:261) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:185) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:164) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:269) ... 26 more caused by: java.lang.reflect.malformedparameterizedtypeexception @ sun.reflect.generics.reflectiveobjects.parameterizedtypeimpl.validateconstructorarguments(unknown source) @ sun.reflect.generics.reflectiveobjects.parameterizedtypeimpl.<init>(unknown source) @ sun.reflect.generics.reflectiveobjects.parameterizedtypeimpl.make(unknown source) @ sun.reflect.generics.factory.corereflectionfactory.makeparameterizedtype(unknown source) @ sun.reflect.generics.visitor.reifier.visitclasstypesignature(unknown source) @ sun.reflect.generics.tree.classtypesignature.accept(unknown source) @ sun.reflect.generics.repository.classrepository.getsuperinterfaces(unknown source) @ java.lang.class.getgenericinterfaces(unknown source) @ org.springframework.core.generictyperesolver.gettypevariablemap(generictyperesolver.java:161) @ org.springframework.core.generictyperesolver.resolvereturntype(generictyperesolver.java:99) @ org.springframework.beans.generictypeawarepropertydescriptor.getpropertytype(generictypeawarepropertydescriptor.java:88) @ org.springframework.beans.typeconverterdelegate.convertifnecessary(typeconverterdelegate.java:138) @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:386) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.convertforproperty(abstractautowirecapablebeanfactory.java:1289) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1250) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1010) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:472) ... 35 more

employeedao.java

bundle com.javatpoint; import org.springframework.orm.hibernate3.hibernatetemplate; public class employeedao { hibernatetemplate template; public void settemplate(hibernatetemplate template) { this.template = template; } public void saveemployee(employee e){ template.save(e); } public void updateemployee(employee e){ template.update(e); } public void deleteemployee(employee e){ template.delete(e); } }

employee.java

package com.javatpoint; public class employee { private int id; private string name; private float salary; public int getid() { homecoming id; } public void setid(int id) { this.id = id; } public string getname() { homecoming name; } public void setname(string name) { this.name = name; } public float getsalary() { homecoming salary; } public void setsalary(float salary) { this.salary = salary; } }

inserttest.java

package com.javatpoint; import org.springframework.beans.factory.beanfactory; import org.springframework.beans.factory.xml.xmlbeanfactory; import org.springframework.core.io.classpathresource; import org.springframework.core.io.resource; public class inserttest { public static void main(string[] args) { resource r=new classpathresource("applicationcontext.xml"); beanfactory factory=new xmlbeanfactory(r); employeedao dao=(employeedao)factory.getbean("d"); employee e=new employee(); e.setid(147); e.setname("kumar"); e.setsalary(70000); //dao.saveemployee(e); dao.updateemployee(e); } }

applicationcontext.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource"> <property name="driverclassname" value="com.microsoft.sqlserver.jdbc.sqlserverdriver"></property> <property name="url" value="jdbc:sqlserver://localhost:1433;database=userinfo"></property> <property name="username" value="sa"></property> <property name="password" value="uid"></property> </bean> <bean id="mysessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="datasource" ref="datasource"></property> <property name="mappingresources"> <list> <value>employee.hbm.xml</value> </list> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.sqlserverdialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="template" class="org.springframework.orm.hibernate3.hibernatetemplate"> <property name="sessionfactory" ref="mysessionfactory"></property> </bean> <bean id="d" class="com.javatpoint.employeedao"> <property name="template" ref="template"></property> </bean> </beans>

employee.hbm.xml

<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.javatpoint.employee" table="emp599"> <id name="id"> <generator class="assigned"></generator> </id> <property name="name"></property> <property name="salary"></property> </class> </hibernate-mapping>

java xml spring hibernate

No comments:

Post a Comment