attempt to create saveOrUpdate event with null entity

u010353901 2014-07-17 08:53:51
HTTP Status 500 - attempt to create saveOrUpdate event with null entity

type Exception report

message attempt to create saveOrUpdate event with null entity

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

exception

java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:40)
org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:23)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:693)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
com.douban.DAOImpl.userDAOImpl.saveuser(userDAOImpl.java:140)<-----错误提示
com.douban.serviceImpl.UserServiceImpl.saveUser(UserServiceImpl.java:71)
com.douban.action.RegisterAction.execute(RegisterAction.java:28)

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


package com.douban.DAOImpl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.douban.DAO.UserDAO;
import com.douban.bean.User;

public class userDAOImpl extends HibernateDaoSupport implements UserDAO {
<!--下面只用到这么一个方法>
public void saveuser(User user) {
this.getHibernateTemplate().saveOrUpdate(user);
}
}




package com.douban.serviceImpl;

import java.util.List;

import com.douban.DAO.UserDAO;
import com.douban.bean.User;
import com.douban.service.UserService;

public class UserServiceImpl implements UserService{
private UserDAO userDAO;
private User user;


public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public UserDAO getUserDAO() {
return userDAO;
}

public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}

public void saveUser(User user) {
this.userDAO.saveuser(user);

}
}

register.jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>register.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<style>
#register {
width: 90%;
height: 300px;
background-image: url("./image/001.jpg");
float: left;
margin: 0 auto; /*居中*/
}

#register table {
wjfth: 90%;
/*<!--background-image:url("./image/00.jpg");-->*/
float: left;
}

#111 {
float: right;
margin-right: 2px
}

.12 {
float: right;
}
</style>
<script language="javascript">
function test(){
var sex=document.getElementsByName("userSex");
if (sex[0].checked == true){
alert(sex[0].value);
}else if(sex[1].checked == true){
alert(sex[1].value);
}else{
alert('你还没选呢');
}
}
</script>
<body>
<jsp:include page="top.jsp"></jsp:include>

<div id="register">

<table style="float: center;margin: 20px;">
<tr>
<td class="11">
<form action="Register.action" method="post">
<h4>请填写注册信息</h4>
用 戶 名:<input id="111" type="text" name="username" size="20"><br>
邮    箱:<input id="111" type="text"
name="email" size="20"><br>
密    码:<input id="111" type="password"
name="password" size="20"> <br> 确认密码:<input id="111"
type="password" name="repassword" size="20"><br>
性    别:<input value="男" id="userSex"
type="radio">男<input id="userSex" type="radio" value="女">女<br>
<!-- 兴趣爱好:<input id="111" type="checkbox" name="intersting" value="画画" size="20"/>
<input id="111" type="checkbox" name="intersting" value="看书" size="20"/>
<input id="111" type="checkbox" name="intersting" value="爬山" size="20"/>
<input id="111" type="checkbox" name="intersting" value="其他" size="20"/><br> -->
<!-- 跳转到个人主页 -->
<input type="submit" onclick="test()" value="注册">

</form></td>
</tr>
<tr class="12">
<td class="12"><a href="logon.jsp">已有账号请登录...</a>
</td>
</tr>
</table>
<%
String name=request.getParameter("username");
String email=request.getParameter("email");
String password=request.getParameter("password");
String sex=request.getParameter("usersex");
/* String intersting=request.getParameter("interstig"); */
%>
</div>
<div id="register-right"></div>
</body>
</html>


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="default" namespace="" extends="struts-default">

<action name="Register" class="RegisterAction" >
<result name="success">/register.jsp</result>
</action>

<action name="LoginAction" class="LoginAction">
<result name="success">/mainPage.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">

<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>

<property name="url">
<value>jdbc:mysql://localhost:3306/douban</value>
</property>

<property name="username">
<value>root</value>
</property>

<property name="password">
<value>986681543</value>
</property>

</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource">
<ref local="dataSource" />
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>

<property name="mappingResources">
<list>
<value>com/douban/bean/user.hbm.xml</value>
<value>com/douban/bean/Score.hbm.xml</value>
<value>com/douban/bean/PlayerType.hbm.xml</value>
<value>com/douban/bean/MovieType.hbm.xml</value>
<value>com/douban/bean/MovieMessage.hbm.xml</value>
<value>com/douban/bean/makePlace.hbm.xml</value>
<value>com/douban/bean/FilmAliasNames.hbm.xml</value>
<value>com/douban/bean/comment.hbm.xml</value>
<value>com/douban/bean/BeanColumn.hbm.xml</value>
<value>com/douban/bean/ActorMessage.hbm.xml</value>
</list>
</property>

</bean>
<!-- 添加hibernTemplate Bean属性-->
<!-- <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> -->

<!-- DAO配置 -->
<bean id="userDao" class="com.douban.DAOImpl.userDAOImpl" scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="RegisterAction" class="com.douban.action.RegisterAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
...全文
354 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
u010353901 2014-07-17
  • 打赏
  • 举报
回复
我利用的是SSH2框架做的,问题出在DAO层,插入数据出了问题怎么调都插不进去数据。我是在userDAO中继承了HibernateDAOSupport。然后在Java中直接用this.getHibernateTemplete().save(user);但是就是插不进数据。求帮忙指导。。。

790

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 其他移动相关
社区管理员
  • 移动开发其他问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧