spring - Saving an object via getSessionFactory().getCurrentSession().save(item) -
even if operation seems extremely used haven't found problem in code. in dao class have:
public class itemdaoimpl extends hibernatedaosupport implements itemdao { @transactional public void additem(item item){ getsessionfactory().getcurrentsession().save(item); } @transactional(readonly = true) public list<item> findallitem(){ return getsessionfactory().getcurrentsession().createquery("from item").list(); }} findallitem() works well, whereas additem() doesn't. when click button invokes additem() following error thrown:
java.lang.classcastexception: com.z.item.model.item cannot cast java.util.map javax.faces.el.evaluationexception: java.lang.classcastexception: com.z.item.model.item cannot cast java.util.map @ javax.faces.component.methodbindingmethodexpressionadapter.invoke(methodbindingmethodexpressionadapter.java:98) @ com.sun.faces.application.actionlistenerimpl.processaction(actionlistenerimpl.java:98) @ javax.faces.component.uicommand.broadcast(uicommand.java:311) . . .
but haven't specified map use object "item" everywhere. item object passed additem() correct. why exception thrown?
here how configure it:
<hibernate-mapping> <class entity-name="com.z.item.model.item" table="item"> <id name="id" type="long"> <column name="id" /> <generator class="identity" /> </id> <property name="name" type="string"> <column name="itemname" length="45" not-null="true" /> </property> <property name="amount" type="int"> <column name="amount" not-null="true" /> </property> <property name="price" type="java.math.bigdecimal"> <column name="price" length="10" not-null="true" /> </property> </class> </hibernate-mapping> <tx:annotation-driven transaction-manager="transactionmanager"/> <bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="datasource"></property> </bean> <bean id="itemdao" class="com.z.item.dao.impl.itemdaoimpl" > <property name="sessionfactory" ref="sessionfactory"></property> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean"> <property name="datasource"> <ref bean="datasource"/> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.hsqldialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingresources"> <list> <value>com/z/item/hibernate/item.hbm.xml</value> </list> </property> </bean>
i don't think issue caused hibernate. issue may have happened when click button , before reaching additem(). likely, data mapping issue(i assume map data item first when clicking button). try print out item before call additem(), should see above exception not calling additem().
Comments
Post a Comment