首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

SSH用户注册老报attempt to create saveOrUpdate event with null entity这个,该怎么处理

2012-01-22 
SSH用户注册老报attempt to create saveOrUpdate event with null entity这个代码都在这儿求给为大侠给瞅

SSH用户注册老报attempt to create saveOrUpdate event with null entity这个
代码都在这儿求给为大侠给瞅瞅
数据库里有一个user表,三个字段id,username,password
_________________________________
User.java:
public class User implements java.io.Serializable
{
private int id;
private String username;
private String password;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public User(String username, String password)
{
super();
this.username = username;
this.password = password;
}

}
___________________________________________________
UserDao.java

public interface UserDao
{
public abstract boolean addUser(User user);
}
---------------------
UserDaoImpl.java
public class UserDaoImpl implements UserDao
{
private SessionFactory sessionFactory;


public void setSessionFactory(SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}

@Override
public boolean addUser(User user)
{
try {
HibernateTemplate hibernateTemplate =new HibernateTemplate(sessionFactory);
hibernateTemplate.saveOrUpdate(user);
return true;
} catch (DataAccessException e) {
e.printStackTrace();
return false;
}

}

}
--------------------------
RegisterAction.java:

{
private User user;
private UserDaoImpl userDaoImpl;

public User getUser()
{
return user;
}

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

public void setUserDaoImpl(UserDaoImpl userDaoImpl)
{
this.userDaoImpl = userDaoImpl;
}

@Override
public String execute() throws Exception
{
if(userDaoImpl.addUser(user))
return SUCCESS;
else
return INPUT;
}

}
---------------------
applicationContext.xml:
<?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-3.0.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/spring_hibernate</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123321</value>
</property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>

<bean id="userDaoImpl" class="com.jeedroid.daoimpl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<bean id="registerAction" class="com.jeedroid.action.RegisterAction">


<property name="userDaoImpl">
<ref local="userDaoImpl"/>
</property>
</bean>
</beans>
--------------------------------------------
struts配置文件:
<struts>

  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <constant name="struts.devMode" value="true" />

  <package name="struts2" extends="struts-default">  
  <action name="register" class="registerAction">  
  <result name="success">/success.jsp</result>  
  <result name="input">/register.jsp</result>  
  </action>  
</package>  
</struts>
--------------------------------------------
User.hbm.xml:
<hibernate-mapping package="com.jeedroid.model">
<class name="User" table="user">
  <id name="id" >
  <generator class="native"/>
  </id>
  <property name="username"/>
  <property name="password"/>
  </class>
</hibernate-mapping>

[解决办法]
页面呢?接收参数正确没有?
[解决办法]
你是谁,不会是我同学吧。。。
麻烦报错信息总要发一下的吧
[解决办法]
报空啊··根据调试看看哪里开始出错的。。。实体

热点排行