(******)struts+hibernate+oracle9i在添加程序与修改程序中包错,请大家帮下忙,多谢(******)
(******)struts+hibernate+oracle9i在添加程序与修改程序中包错,请大家帮下忙,多谢(******)
Userlist.hbm.xml
里面映射的id如下,数据库是oracle9i,id在表里的类型是number(20)
<id name= "id " type= "java.lang.String ">
<column name= "ID " precision= "20 " scale= "0 " />
<generator class= "increment " />
</id>
1、当type= "java.lang.String "时,更新程序传过去的id值不错,但是添加是出错
错误是
------------------------------------------------
javax.servlet.ServletException: this id generator generates long, integer, short
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.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.newstong.web.filters.SetEncodingFilter.doFilter(SetEncodingFilter.java:62)
root cause
org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short
org.hibernate.id.IdentifierGeneratorFactory.createNumber(IdentifierGeneratorFactory.java:119)
org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:47)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)
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)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
com.newstong.web.struts.action.AddStudent.execute(AddStudent.java:87)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.newstong.web.filters.SetEncodingFilter.doFilter(SetEncodingFilter.java:62)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
----------------------------------------------------
2、当type= "java.lang.Long "时,是添加是不出错,但更新程序传过去的id值出错,
错误是
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.String
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.newstong.web.filters.SetEncodingFilter.doFilter(SetEncodingFilter.java:62)
root cause
java.lang.ClassCastException: java.lang.String
org.hibernate.type.LongType.set(LongType.java:40)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
org.hibernate.loader.Loader.doQuery(Loader.java:390)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
com.newstong.domain.Userlist$$EnhancerByCGLIB$$dcc6eea3.getUsername( <generated> )
org.apache.jsp.updatestu_jsp._jspService(updatestu_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.newstong.web.filters.SetEncodingFilter.doFilter(SetEncodingFilter.java:62)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------
[解决办法]
Userlist stu = (Userlist) s.load(Userlist.class, id);
-->
Userlist stu = (Userlist) s.load(Userlist.class, new Long(id));
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html