日期:2014-05-17  浏览次数:20780 次

ssh框架问题困扰我好几天了啊
我插入数据两张表一对一的主键关联,服务器启动以后第一次可以插入数据,第二次就提示主键重复,在重启服务器以后,第一条可以插入,第二条又提示主键重复了啊!郁闷啊!!!
这是save方法,LoginId是用户名不是seq
@Transactional(propagation=Propagation.REQUIRED)
public String add(){
logger.info("add user access");
UserDAO userDao = (UserDAO)applicationContext.getBean("userDAO");
user.setLoginId(user.getLoginId());
user.setPassword(genRandomPassword(8));
user.setStatus((short)1);
user.setCategory(user.getCategory());
Date date = new Date();
user.setLastLogin(date);
individual.setCreateBy(1);
individual.setFristName(individual.getFristName());
individual.setLastName(individual.getLastName());
individual.setGreeting(mr);
individual.setCreateTime(new Date());
individual.setEmail(individual.getEmail());
individual.setEmailVerified(false);
user.setIndividual(individual);
userDao.save(user);
return "success";
}
错误异常:
Struts Problem Report

Struts has detected an unhandled exception:
Messages:

  Duplicate entry '122' for key 1
  Could not execute JDBC batch update
  Could not execute JDBC batch update; SQL [insert into aicloud_poc.User (LoginID, Password, LastLogin, Status, Category, ProfileID, Seq) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

File: com/mysql/jdbc/ServerPreparedStatement.java
Line number: 665
Stacktraces
org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into aicloud_poc.User (LoginID, Password, LastLogin, Status, Category, ProfileID, Seq) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

  org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:643)



xml配置文件 user
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 29, 2012 12:01:12 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
  <class name="cn.com.aicontrol.aicloud.entity.User" table="User" catalog="aicloud_poc" dynamic-update="true">
  <meta attribute="generated-class" inherit="false">cn.com.aicontrol.aicloud.entity.AbstractUser</meta>
  <meta attribute="scope-class" inherit="false">public abstract</meta>
  <id name="seq" type="java.lang.Integer">
  <column name="Seq" />
  <generator class="foreign">
  <param name="property">individual</param>
  </generator>
  </id>
  <one-to-one name="individual" class="cn.com.aicontrol.aicloud.entity.Individual" constrained="true" cascade="all" lazy=&