问题描述
- spring问题,事务提交阶段显示主键ID为0,插入数据库失败
- struts2+hibernate4创建了一个注册系统,本来没问题的,但是整合加入spring之后在注册报空指针异常,在事务提交阶段取到的userId为0.感觉就是在new user()那里出问题,但是一直找不到问题根源困扰好久,*.hbm.xml,实体类都没问题,就是事务提交主键ID老是提示为0,怎么解决
实体类文件
package com.chengji.ssh.beans;public class User {
private String username;private String password;
private int gender;
private int userId;
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 int getGender() {
return gender;
}
public void setGender(int gender) {
this.gender = gender;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}
*.hbm.xml文件
<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE hibernate-mapping PUBLIC
-//Hibernate/Hibernate Mapping DTD 3.0//EN""
http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"">not-null=""true"" length=""16"">
not-null=""true"" length=""16"" />
length=""1"" />
解决方案
页面上的代码是什么样的呢,userid那个标签的name写对了么,有对应的value么