【发布时间】:2014-09-09 11:02:01
【问题描述】:
您好,我试图解决,但我没有解决它
像这样得到异常
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session:
[com.omnypay.dao.bo.CloudSvrUsersProfile#284]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.omnypay.dao.bo.CloudSvrUsersProfile#284]
原因:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was
already associated with the session:
我的用户类别是
@Entity
@Table(name="CLOUD_SVR_USERS")
@NamedQuery(name="CloudSvrUser.findAll", query="SELECT c FROM CloudSvrUser c")
public class CloudSvrUser implements Serializable {
@Id
@GeneratedValue
@Column(name="USER_ID")
private long userId;
it has some column and the oneto one relation like
@OneToOne(mappedBy="user",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
private CloudSvrUsersProfile usersProfile;
and getters&setters
我的个人资料课程是
@Entity
@Table(name="CLOUD_SVR_USERS_PROFILE1")
@NamedQuery(name="CloudSvrUsersProfile.findAll", query="SELECT c FROM CloudSvrUsersProfile c")
public class CloudSvrUsersProfile implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="USER_ID",nullable=false)
@GeneratedValue(generator="gen")
@GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="user"))
private Long usersProfileId;
//columns and
@OneToOne
@PrimaryKeyJoinColumn
private CloudSvrUser user;
@Transient
private String emailId;
服务实现类是
@Transactional
public void UpdateUserProfile(CloudSvrUsersProfile userProf) throws BusinessException
{
try{
CloudSvrUser dbUser = getUser(userProf);
//CloudSvrUsersProfile dbUserProfile = dbUser.getUsersProfile();
//CloudSvrUsersProfile updatedProf=userProf.getUsersProfile();
if(dbUser != null){
//CloudSvrUsersProfile newUserInfoList = new CloudSvrUsersProfile();
//CloudSvrUsersProfile newUserInfoList = CloudSvrUsersProfile();
CloudSvrUsersProfile updatedProf = new CloudSvrUsersProfile();
updatedProf.setFirstName(userProf.getFirstName());
updatedProf.setLastName(userProf.getLastName());
updatedProf.setAddress1(userProf.getAddress1());
updatedProf.setAddress2(userProf.getAddress2());
updatedProf.setAddress3(userProf.getAddress3());
updatedProf.setZipCode(userProf.getZipCode());
updatedProf.setState(userProf.getState());
//
updatedProf.setStatus(Long.parseLong("1"));
updatedProf.setCreatedBy(Long.parseLong("1"));
updatedProf.setCreatedDate(new Timestamp(System.currentTimeMillis()));
//updatedProf.setEmialId(userProf.getEmialId());
dbUser.setEmailId(userProf.getEmailId() );
dbUser.setUsersProfile(updatedProf);
updatedProf.setUser(dbUser);
updateuser(dbUser);
}
}
catch(DaoException daoException) {
throw new BusinessException(daoException.getMessage());
}
}
对于第一个请求,它向 db 输入数据,但对于第二个请求,当我更改某些值并尝试从我的 url 中访问 db 时,它给出了上述异常
请帮帮我
【问题讨论】:
-
您的服务等的邮政编码
-
请粘贴导致此问题的代码?
-
try {// super.getHibernateTemplate().save(user); //super.getHibernateTemplate().saveOrUpdate(user); //super.getHibernateTemplate().update(user); //this.userDao.updateUser(dbUser); } catch(DataAccessException accessException){ throw new DaoException("发生内部数据库错误。"); }
-
这是我的 dao impl 类,我还有 2 个类 user 和 profile 类,我与 userprofile 有一对一的关系
-
@smita 不要将代码添加到 cmets.. instate 编辑您的问题并添加 DAO 和服务类的代码
标签: java spring hibernate session spring-mvc