To update an entity Attribute
, the following piece of code calls the transaction template(and not @Transactional
since only a part of the method to be transactional is required)
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
updateAttributeIsCustom(entry.getKey(), Arrays.asList(createUser, createDate, modifiedUser, modifiedDate, "CustomerKey", "ProfileId", "JobId", "PageSequence"), true);
}
});
The updateAttributeIsCustom
method is as follows:
private void updateAttributeIsCustom(DalDataList dalDataList, List<String> auditableColumnNames, boolean isReset) {
List<DalAttribute> attributes = dalDataList.getAttributes();
DalUser currentUser = attributeDao.getReference(DalUser.class,
coreService.getUserContext().getUserId());
Boolean isCustom = null;
try {
for (DalAttribute attribute : attributes) {
if(!isReset) {
String customValue = String.valueOf(!auditableColumnNames.contains(attribute.getName()));
if (dalDataList.getListType() == DataListType.TRANSACTION_TABLE && (attribute.getName().equals("CREATED_BY") || attribute.getName().equals("CREATED_DATE"))) {
customValue = "false";
}
isCustom = Boolean.valueOf(customValue);
}
attribute.setCustom(isCustom);
attribute.setModifiedBy(currentUser);
attributeDao.update(attribute);
}
} catch (Exception e) {
logger.error("Error occured during during updation of list with id {}. Attribute Sync is required.", dalDataList.getId());
}
}
Now when this piece of code is executed, it works very well in my local environment. But, this fails in a higher environment with the same data set stating the following error:
java.lang.Exception: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly\n\tat
The transaction is not set to rollBackOnly explicitly anywhere. The error occurs only when the isReset is true and when it is false it works fine. What possibly could cause this error?