0

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?

Arun
  • 1,176
  • 5
  • 20
  • 48
  • Possible duplicate of http://stackoverflow.com/questions/19302196/transaction-marked-as-rollback-only-how-do-i-find-the-cause?rq=1 – Ivan Pronin Apr 11 '17 at 19:00
  • I have checked the above mentioned answer as well. That solution doesn't work for me because I use transactionTemplate inside the medthod and not @Transactional. Though both means the same, I doubt the solution can be used for my case. – Arun Apr 11 '17 at 19:05

0 Answers0