hibernate 异常处理


ids for this class must be manually assigned before calling save(),
User.hbm.xml  中主键生成设置是   <generator class="assigned"></generator>
hibernate 这个错误的原因可能是,表中已经有个主键(id)。 但是插入的(调用save)时那个值是null
User user_ = new User();
//user_.setUser_id(id);这一句注释才出现这个错误,id值是页面传进来的,没有给User对象赋值,相当于插入主键值为null,才出现这样的错误。
具体异常如下:

javax.servlet.ServletException: ids for this class must be manually assigned before calling save(): com.cn.bireport.domain.User; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.cn.bireport.domain.User
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:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.cn.bireport.common.CharacterEncodeFilter.doFilter(CharacterEncodeFilter.java:41)

你可能感兴趣的:(java,apache,Hibernate,struts,servlet)