日期:2014-05-18  浏览次数:20775 次

ssh
ssh简单问题:调用NewsDAO里面操作数据库的方法出错, 
简单描述一下我的相关代码: 

NewsAction: 
public class NewsAction extends DispatchAction { 

  //删除信息 
public ActionForward deleteNews(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response) { 

String nids[] = request.getParameterValues("nid"); 
int cid = -1; 
  int nid = Integer.parseInt(nids[0]); 
  newsDao.findNewByNid(nid); 
............ 
applicationContext.xml 

<bean name="/news" class="com.aso.struts.action.NewsAction" 
abstract="false" lazy-init="default" autowire="default" 
dependency-check="default"> 
<property name="newsDao"> 
<ref bean="NewsDAO" /> 
</property> 
<property name="newsPaging"> 
<ref bean="NewsPaging" /> 
</property> 
</bean> 

NewsDAO: 
public News findNewByNid(int nid) 

log.debug("getting News instance with nid"); 
try { 
News instance = (News) getHibernateTemplate().find("from News as news where news.nid="+nid); 
return instance; 
} catch (RuntimeException re) { 
log.error("get failed", re); 
throw re; 



---------------------运行报错位置------------------------ 
newsDao.findNewByNid(nid); 

---------------------报错信息---------------------------- 

严重: Servlet.service() for servlet action threw exception 
java.lang.ClassCastException: java.lang.String 
at org.hibernate.type.TimestampType.isEqual(TimestampType.java:77) 
at org.hibernate.type.NullableType.isEqual(NullableType.java:160) 
at org.hibernate.type.AbstractType.isSame(AbstractType.java:104) 
at org.hibernate.type.AbstractType.isDirty(AbstractType.java:70) 
at org.hibernate.type.NullableType.isDirty(NullableType.java:186) 
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476) 
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2803) 
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:467) 
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:190) 
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113) 
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195) 
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76) 
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26) 
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985) 
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390) 
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373) 
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840) 
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:83