package com.yixing.data.dao.daoimpl;
import java.util.List;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.yixing.data.dao.ISinglePaperDAO;
import com.yixing.data.po.FaInfo;
import com.yixing.data.po.SinglePaper;
public class SinglePaperDAO extends HibernateDaoSupport implements ISinglePaperDAO {
private static final String FIND_SinglePaper = "from SinglePaper where faInfo=? ";
public List findSinglePaper(int faid,byte famc) {
List list=this.getHibernateTemplate().find(FIND_SinglePaper,faid);
if(list.isEmpty())
{
Session session=this.getHibernateTemplate().getSessionFactory().getCurrentSession();
FaInfo fainfo =(FaInfo)session.load(FaInfo.class,Integer.valueOf(faid));
//新建默认三条记录
SinglePaper sp1 =new SinglePaper(1,famc);
SinglePaper sp2 =new SinglePaper(2,famc);
SinglePaper sp3 =new SinglePaper(3,famc);
sp1.setFaInfo(fainfo);
sp2.setFaInfo(fainfo);
sp3.setFaInfo(fainfo);
list.add(sp1);
list.add(sp2);
list.add(sp3);
// 到这里都没有问题
session.save(sp1); //提示这里错
session.save(sp2);
session.save(sp3);
}
return list;
}
public void updateSinglePaper(SinglePaper sp) {
this.getHibernateTemplate().update(sp);
}
}
我用的是jdk1.5+tomcat5.5+mysql5 原来在mssql2000上运行正常 移植到mysql出现下列错误,不知道那里的问题。猜测是那里配置不对
javax.servlet.ServletException: could not insert: [com.yixing.data.po.SinglePaper]
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.yixing.comm.userPwdFilter.doFilter(userPwdFilter.java:58)
com.yixing.comm.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:33)
root cause
org.hibernate.exception.GenericJDBCException: could not insert: [com.yixing.data.po.SinglePaper]
org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1777)
org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)