您好我试图解决但我没有解决它
像这样异常
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;
和服务impl类是
@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时,它给出了上述异常
请帮帮我
答案 0 :(得分:0)
删除
级联= CascadeType.ALL
来自您的用户类。