В этой строке я получаю следующую ошибку:
**data = (VerifiableData) dao.merge(data);**
Я получаю следующую ошибку:
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Объекткласс [com.data.dataobject.transaction.Trade] с идентификатором [1123520]: оптимистическая блокировка не удалась;вложенное исключение: org.hibernate.StaleObjectStateException: строка была обновлена или удалена другой транзакцией (или сопоставление несохраненного значения было неверным): [com.data.dataobject.transaction.Trade # 1123520]
ОбязательноФункция:
@SuppressWarnings("unchecked")
public void verify(SnapshotData sd) throws SameMakerCheckerException {
if (sd == null) {
throw new IllegalArgumentException(
"Invalid SnapshotData, null not allowed");
}
VerifiableData data = sd.getData();
if (data == null) {
throw new IllegalArgumentException(
"Invalid VerifiableData, null not allowed");
}
if (data.getId() == null) {
throw new IllegalArgumentException(
"Invalid VerifiableData, null id not allowed");
}
if (data.getVersion() == null) {
throw new IllegalArgumentException(
"Invalid VerifiableData, null version not allowed");
}
GenericDao dao = daoFactory.getGenericDao(data.getClass());
if (dao.contains(data)) {
throw new IllegalArgumentException(
"Invalid VerifiableData, managed object not allowed");
}
try {
DataRef dr = data.getDataRef();
PendingData pd = pdDao.findLatestByTypeAndId(
(Class<? extends VerifiableData>) dr.getType(), dr.getId(),
sd.getOperation());
if (pd == null) {
throw new OptimisticLockingFailureException(
CONCURRENT_UPDATE_ERROR);
}
if (StringUtils.equalsIgnoreCase(UserUtils.getCurrentUser(),
pd.getLastChangedUser())) {
throw new SameMakerCheckerException();
}
PendingDataStatus status = pd.getStatus();
if (PendingDataStatus.PENDING_ADD.equals(status)) {
ListenerUtils.executeDataLifeCycleListener(PreVerifyAdd.class,
data, pd.getOperation());
} else if (PendingDataStatus.PENDING_UPDATE.equals(status)) {
ListenerUtils.executeDataLifeCycleListener(
PreVerifyUpdate.class, data, pd.getOperation());
} else {
throw new IllegalArgumentException(
"Invalid PendingData, unexpected status: " + status);
}
data = (VerifiableData) dao.merge(data); // Issue at this line
sd.setData(data);
try {
dao.flush();
} catch (StaleObjectStateException soe) {
throw new OptimisticLockingFailureException(
CONCURRENT_UPDATE_ERROR);
} catch (LockAcquisitionException lae) {
throw new OptimisticLockingFailureException(
CONCURRENT_UPDATE_ERROR);
}
pd = pdDao.merge(pd);
pd.setStatus(PendingDataStatus.VERIFIED);
try {
pdDao.flush();
} catch (StaleObjectStateException soe) {
throw new OptimisticLockingFailureException(
CONCURRENT_UPDATE_ERROR);
}
} catch (SameMakerCheckerException e) {
throw e;
} catch (Exception e) {
handleException(e);
}
}
// Класс снимка
public class SnapshotData {
private VerifiableData data;
private String operation;
public final VerifiableData getData() {
return data;
}
public final String getOperation() {
return operation;
}
public final void setData(VerifiableData data) {
this.data = data;
}
public final void setOperation(String operation) {
this.operation = operation;
}
}
// Класс VerifiableData
@DataLifeCycleListener(listener = { VerifiableDataListener.class })
@MappedSuperclass
public abstract class VerifiableData extends Data {
@Column(name = "CREATION_TIME")
private Timestamp creationTime;
@Column(name = "CREATION_USER")
@Length(max = 20)
private String creationUser;
@Column(name = "LAST_APPROVED_TIME")
private Timestamp lastApprovedTime;
@Column(name = "LAST_APPROVED_USER")
@Length(max = 20)
private String lastApprovedUser;
@Column(name = "LAST_CHANGED_TIME")
private Timestamp lastChangedTime;
@Column(name = "LAST_CHANGED_USER")
@Length(max = 20)
private String lastChangedUser;
@Override
public Object clone() throws CloneNotSupportedException {
VerifiableData vd = (VerifiableData) super.clone();
if (creationTime != null) {
vd.creationTime = (Timestamp) creationTime.clone();
}
if (lastApprovedTime != null) {
vd.lastApprovedTime = (Timestamp) lastApprovedTime.clone();
}
if (lastChangedTime != null) {
vd.lastChangedTime = (Timestamp) lastChangedTime.clone();
}
return vd;
}
public Timestamp getCreationTime() {
return creationTime;
}
public String getCreationUser() {
return creationUser;
}
public Timestamp getLastApprovedTime() {
return lastApprovedTime;
}
public String getLastApprovedUser() {
return lastApprovedUser;
}
public Timestamp getLastChangedTime() {
return lastChangedTime;
}
public String getLastChangedUser() {
return lastChangedUser;
}
@Override
public int hashCode() {
return new HashCodeBuilder().appendSuper(super.hashCode()).append(
creationTime).append(creationUser).append(lastApprovedTime)
.append(lastApprovedUser).append(lastChangedTime).append(
lastChangedUser).toHashCode();
}
public void setCreationTime(Timestamp creationTime) {
this.creationTime = creationTime;
}
public void setCreationUser(String creationUser) {
this.creationUser = creationUser;
}
public void setLastApprovedTime(Timestamp lastApprovedTime) {
this.lastApprovedTime = lastApprovedTime;
}
public void setLastApprovedUser(String lastApprovedUser) {
this.lastApprovedUser = lastApprovedUser;
}
public void setLastChangedTime(Timestamp lastChangedTime) {
this.lastChangedTime = lastChangedTime;
}
public void setLastChangedUser(String lastChangedUser) {
this.lastChangedUser = lastChangedUser;
}
}
public SnapshotData verifyTradeinBulkAmend (Trade trade) выдает SameMakerCheckerException {
SnapshotData sd = new SnapshotData();
sd.setData(trade);
sd.setOperation(ConstantValue.PENDING_DATA_OPERATION_AMEND);
coreServiceLookup.getSnapshotDataService().verify(sd);
return sd;
}