Получение исключений OptimisticLockException и StaleObjectStateException, когда у обновляемой сущности включено кеширование. Кеширование вызывает эту проблему?
Получено следующее исключение при попытке создать обращение:
Вызвано: javax.transaction.RollbackException: ARJUNA016053: не удалось зафиксировать транзакцию. atcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1243)atcom.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126) в. arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) в org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:91) [jboss-as-e redhat-1.jar: 7.5.20.Final-redhat-1] ... еще 92 Причина: javax.persistence.OptimisticLockException: строка была обновлена или удалена другой транзакцией (или отображение несохраненных значений было неправильным): [uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhHeader#1476654500] в org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:1413) [hibernate-entitymanager-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1] в org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1329) [hibernate-entitymanager-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1] в org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) [hibernate-entitymanager-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1] в org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316) [hibernate-entitymanager-4.2.27.Final -redhat-1.jar: 4.2.27.Final-redhat-1] в org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1510) [hibernate-entitymanager-4.2.27. 1Final-redhat .jar: 4.2.27.Final-redhat-1] в org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:114) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1]nate в org.hibernate. engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.2.27.Final-redhat-1.jar:4.2.27.Final-redhat-1] на com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76) на com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273) на com.arjuna. Координатор.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93) на com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162) на com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1231) ... еще 95
Here is the code:
@Override
public synchronized Integer nextUniqueSequence() {
Integer nextSequenceNumber = Integer.valueOf(0);
MhHeaderBO mhHeader;
mhHeader = getSingleHeader();
nextSequenceNumber = mhHeader.getMhLastUniSeqNum();
nextSequenceNumber = nextSequenceNumber + 1;
mhHeader.setMhLastUniSeqNum(nextSequenceNumber);
updateMhHeader(mhHeader);
return nextSequenceNumber;
}
@Override
public synchronized MhHeaderBO updateMhHeader(MhHeaderBO bo) {
uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhHeader boTmp = Transformer
.transform(
bo,
uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhHeader.class);
boTmp = mhHeaderDM.save(boTmp);
return Transformer.transform(boTmp, MhHeaderBO.class);
}
Организация
package uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import uk.gov.gpn.dwp.cacs.framework.dm.BaseEntity;
/**
* MhHeader This is the HEADER record for the ICA MASTER file used for front end keying.
*
* @see uk.gov.gpn.dwp.cacs.framework.dm.BaseEntity
*/
@Entity
@Table(name = "mh_header")
@Cacheable
@Getter
@Setter
@TypeDefs({
@TypeDef(name = "flattype", typeClass = uk.gov.gpn.dwp.cacs.dm.helpers.FlatType.class)
,
@TypeDef(name = "arraytype", typeClass = uk.gov.gpn.dwp.cacs.dm.helpers.ArrayType.class)
})
public class MhHeader extends BaseEntity implements Serializable {
/**
* Entity property: mhNino8
*/
@Column(name = "mh_nino_8", length = 8)
private String mhNino8;
/**
* Entity property: mhRecType
*/
@Column(name = "mh_rec_type", length = 1)
private String mhRecType;
/**
* Entity property: mhBookRenewalDt
*/
@Column(name = "mh_book_renewal_dt")
@Temporal(TemporalType.DATE)
private Date mhBookRenewalDt;
/**
* Entity property: mhActRenewalDt
*/
@Column(name = "mh_act_renewal_dt")
@Temporal(TemporalType.DATE)
private Date mhActRenewalDt;
/**
* Entity property: mhFstRunOfTxYr
*/
@Column(name = "mh_fst_run_of_tx_yr")
@Temporal(TemporalType.DATE)
private Date mhFstRunOfTxYr;
/**
* Entity property: mhTruncStrtDt
*/
@Column(name = "mh_trunc_strt_dt")
@Temporal(TemporalType.DATE)
private Date mhTruncStrtDt;
/**
* Entity property: mhTruncObWeeks
*/
@Column(name = "mh_trunc_ob_weeks")
private Integer mhTruncObWeeks;
/**
* Entity property: mhLastUpdateDt
*/
@Column(name = "mh_last_update_dt")
@Temporal(TemporalType.DATE)
private Date mhLastUpdateDt;
/**
* Entity property: mhBlockInUse
*/
@Column(name = "mh_block_in_use")
private Integer mhBlockInUse;
/**
* Entity property: mhLastNoUsed
*/
@Column(name = "mh_last_no_used")
private Integer mhLastNoUsed;
/**
* Entity property: mhGbniFlag
*/
@Column(name = "mh_gbni_flag", length = 2)
private String mhGbniFlag;
/**
* Entity property: mhOfficeNum
*/
@Column(name = "mh_office_num")
private Integer mhOfficeNum;
/**
* Entity property: mhADay
*/
@Column(name = "mh_a_day")
@Temporal(TemporalType.DATE)
private Date mhADay;
/**
* Entity property: mhEDt
*/
@Column(name = "mh_e_dt")
@Temporal(TemporalType.DATE)
private Date mhEDt;
/**
* Entity property: mhXDt
*/
@Column(name = "mh_x_dt")
@Temporal(TemporalType.DATE)
private Date mhXDt;
/**
* Entity property: mhLastNiExtDt
*/
@Column(name = "mh_last_ni_ext_dt")
@Temporal(TemporalType.DATE)
private Date mhLastNiExtDt;
/**
* Entity property: mhLatestNiExtYr
*/
@Column(name = "mh_latest_ni_ext_yr")
private Integer mhLatestNiExtYr;
/**
* Entity property: mhLatestS2pExtDt
*/
@Column(name = "mh_latest_s2p_ext_dt")
@Temporal(TemporalType.DATE)
private Date mhLatestS2pExtDt;
/**
* Entity property: mhLatestS2pEndDt
*/
@Column(name = "mh_latest_s2p_end_dt")
@Temporal(TemporalType.DATE)
private Date mhLatestS2pEndDt;
/**
* Entity property: mhLatestS2pExtYr
*/
@Column(name = "mh_latest_s2p_ext_yr")
private Integer mhLatestS2pExtYr;
/**
* Entity property: mhIccMailshotDt
*/
@Column(name = "mh_icc_mailshot_dt")
@Temporal(TemporalType.DATE)
private Date mhIccMailshotDt;
/**
* Entity property: mhReviewInterval
*/
@Column(name = "mh_review_interval")
private Integer mhReviewInterval;
/**
* Entity property: mhLastUniSeqNum
*/
@Column(name = "mh_last_uni_seq_num")
private Integer mhLastUniSeqNum;
/**
* Entity property: mhLastPdcsBcstRecd
*/
@Column(name = "mh_last_pdcs_bcst_recd")
@Temporal(TemporalType.DATE)
private Date mhLastPdcsBcstRecd;
/**
* Entity property: mhLastPdcsFileNo
*/
@Column(name = "mh_last_pdcs_file_no")
private Integer mhLastPdcsFileNo;
/**
* Entity property: mhCccIntInd
*/
@Column(name = "mh_ccc_int_ind", length = 1)
private String mhCccIntInd;
/**
* Entity property: mhLastMonFoilDt
*/
@Column(name = "mh_last_mon_foil_dt")
@Temporal(TemporalType.DATE)
private Date mhLastMonFoilDt;
/**
* Entity property: mhLastWedFoilDt
*/
@Column(name = "mh_last_wed_foil_dt")
@Temporal(TemporalType.DATE)
private Date mhLastWedFoilDt;
/**
* Entity property: mhLimtNoPymnts1
*/
@Column(name = "mh_limt_no_pymnts_1")
private Integer mhLimtNoPymnts1;
/**
* Entity property: mhLimtNoPymnts2
*/
@Column(name = "mh_limt_no_pymnts_2")
private Integer mhLimtNoPymnts2;
/**
* Entity property: mhLimtNoPymnts3
*/
@Column(name = "mh_limt_no_pymnts_3")
private Integer mhLimtNoPymnts3;
/**
* Entity property: mhLimtNoPymnts4
*/
@Column(name = "mh_limt_no_pymnts_4")
private Integer mhLimtNoPymnts4;
/**
* Entity property: mhChqLimtUpper
*/
@Column(name = "mh_chq_limt_upper")
private Integer mhChqLimtUpper;
/**
* Entity property: mhChqLimtLower
*/
@Column(name = "mh_chq_limt_lower")
private Integer mhChqLimtLower;
/**
* Entity property: mhChqDay1
*/
@Column(name = "mh_chq_day1")
private Integer mhChqDay1;
/**
* Entity property: mhBankDmrInd
*/
@Column(name = "mh_bank_dmr_ind", length = 1)
private String mhBankDmrInd;
/**
* Entity property: mhCisIntInd
*/
@Column(name = "mh_cis_int_ind", length = 1)
private String mhCisIntInd;
/**
* Entity property: mhContctWeedPrdcty
*/
@Column(name = "mh_contct_weed_prdcty")
private Integer mhContctWeedPrdcty;
/**
* Entity property: mhCcPrdStrtYr
*/
@Column(name = "mh_cc_prd_strt_yr")
private Integer mhCcPrdStrtYr;
/**
* Entity property: mhNiPrdStrtYr
*/
@Column(name = "mh_ni_prd_strt_yr")
private Integer mhNiPrdStrtYr;
/**
* Entity property: mhHbsPipePiFilSeqNo
*/
@Column(name = "mh_hbs_pipe_pi_fil_seq_no")
private Integer mhHbsPipePiFilSeqNo;
/**
* Entity property: mhHbsPipePsFilSeqNo
*/
@Column(name = "mh_hbs_pipe_ps_fil_seq_no")
private Integer mhHbsPipePsFilSeqNo;
/**
* Entity property: mhHbsPipeLivDt
*/
@Column(name = "mh_hbs_pipe_liv_dt")
@Temporal(TemporalType.DATE)
private Date mhHbsPipeLivDt;
/**
* Entity property: mhDwpWfAccId
*/
@Column(name = "mh_dwp_wf_acc_id", length = 10)
private String mhDwpWfAccId;
/**
* Entity property: mhDwpNonWfAccId
*/
@Column(name = "mh_dwp_non_wf_acc_id", length = 10)
private String mhDwpNonWfAccId;
/**
* Entity property: mhPipEffDt
*/
@Column(name = "mh_pip_eff_dt")
@Temporal(TemporalType.DATE)
private Date mhPipEffDt;
/**
* Entity property: mhUcEffDt
*/
@Column(name = "mh_uc_eff_dt")
@Temporal(TemporalType.DATE)
private Date mhUcEffDt;
/**
* Entity property: mhArEffDt
*/
@Column(name = "mh_ar_eff_dt")
@Temporal(TemporalType.DATE)
private Date mhArEffDt;
/**
* Entity property: mhPayments
*/
@Column(name = "mh_payments_occ", columnDefinition = "_ica_mh_payments_type")
@Type(type = "arraytype", parameters = {
@Parameter(name = "class", value = "uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhPayments")})
private List<MhPayments> mhPayments = new ArrayList<MhPayments>();
/**
* Entity property: mhEarnings
*/
@Column(name = "mh_earnings_occ", columnDefinition = "_ica_mh_earnings_type")
@Type(type = "arraytype", parameters = {
@Parameter(name = "class", value = "uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhEarnings")})
private List<MhEarnings> mhEarnings = new ArrayList<MhEarnings>();
/**
* Entity property: mhWfDets
*/
@Column(name = "mh_wf_dets_occ", columnDefinition = "_ica_mh_wf_dets_type")
@Type(type = "arraytype", parameters = {
@Parameter(name = "class", value = "uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhWfDets")})
private List<MhWfDets> mhWfDets = new ArrayList<MhWfDets>();
/**
* Entity property: mhGiroNums
*/
@Column(name = "mh_giro_nums_occ", columnDefinition = "_ica_mh_giro_nums_type")
@Type(type = "arraytype", parameters = {
@Parameter(name = "class", value = "uk.gov.gpn.dwp.cacs.dm.entity.icamastheader.entity.MhGiroNums")})
private List<MhGiroNums> mhGiroNums = new ArrayList<MhGiroNums>();
}