gpt4 book ai didi

java - org.springframework.orm.hibernate3.HibernateSystemException : a different object with the same identifier value was already associated with the session

转载 作者:太空宇宙 更新时间:2023-11-04 14:34:37 25 4
gpt4 key购买 nike

您好,我尝试解决,但未能解决

像这样异常

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());
}

}

对于第一个请求,它将数据输入到数据库,但第二个请求,当我更改某些值并尝试从我的网址访问数据库时,它给出了上述异常

请帮助我

最佳答案

删除

级联=CascadeType.ALL

来自您的 User 类。

关于java - org.springframework.orm.hibernate3.HibernateSystemException : a different object with the same identifier value was already associated with the session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25742984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com