当前位置: 代码迷 >> J2EE >> org.hibernate.PropertyValueException: not-null property references a
  详细解决方案

org.hibernate.PropertyValueException: not-null property references a

热度:404   发布时间:2016-04-22 03:27:34.0
hibernates删除数据的问题
jsp页面1

<%@ page language="java" import="java.util.*,org.hibernate.Session,
org.hibernate.Transaction,com.SessionFactory,org.hibernate.Query,
org.hibernate.cfg.Configuration,com.orm.Adminuser" pageEncoding="gb2312"%>

<%



Session s = SessionFactory.getSession();
Query q = s.createQuery("from Adminuser");
List list = q.list();
if(list.isEmpty())
out.print("error!");
else
{  
for (Iterator it = list.iterator(); it.hasNext(); ) 
{
  Adminuser ui = (Adminuser) it.next();
  out.println(ui.getId());
  out.println(ui.getLoginname());
  out.println(ui.getTruename());
   
out.print("<a href=adminupdate.jsp?id="+ui.getId()+">编辑</a>");  
out.print("<a href=admindel.jsp?id="+ui.getId()+">删除</a>");
  out.println("<BR>");
  }
}
s.close();



%>




jsp页面2为(我想从页面1传ID的值到这个页面,通过ID判断删除的具体行)

<%@ page language="java" import="java.util.*,org.hibernate.Session,
org.hibernate.Transaction,com.SessionFactory,org.hibernate.Query,
org.hibernate.cfg.Configuration,com.orm.Adminuser" pageEncoding="GBK"%>
<%request.setCharacterEncoding("GBK");%>
<%
long id=Long.parseLong(request.getParameter("id"));
Session s = SessionFactory.getSession();
org.hibernate.Transaction t = s.beginTransaction();
Adminuser u1=new Adminuser();
u1.setId(new Long(id));
s.delete(u1);
t.commit();
s.close();
 %>  


结果提示错误了!




如下:
HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /admindel.jsp at line 11

8: org.hibernate.Transaction t = s.beginTransaction();
9: Adminuser u1=new Adminuser();
10: u1.setId(new Long(id));
11: s.delete(u1);
12: t.commit();
13: s.close();
14:  


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.orm.Adminuser.loginname
org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:173)
org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:110)
org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:761)
org.hibernate.impl.SessionImpl.delete(SessionImpl.java:739)
org.apache.jsp.admindel_jsp._jspService(admindel_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
  相关解决方案