79255493

Date: 2024-12-05 16:33:48
Score: 0.5
Natty:
Report link

Thanks @Sve Kamenska and @M.Denium. However this does not work for me.

I tried the following.

    @Transactional(transactionManager = "standardizedDataSourceTransactionManager", propagation = Propagation.REQUIRES_NEW)
    public void callMe() {
        try {
            boolean retVal = flattenProcessingInfoService.processSave1(1001, 2001, "MyHost");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
And called CallMe() method from another one multiple times. I am not reaching e.printStackTrace at all.

This is the case when I have repository.save()

But when I have native query..

   @Modifying
   @Transactional
   @Query(value = "INSERT INTO pega_data.T_FLATTEN_PROCESSING_INFO (host_id, begin_version, end_version, processing_dt_tm) VALUES " +
           "(:hostName, :beginVersion, :endVersion, :processingDateTime)", nativeQuery = true)
   void insertBatch(String hostName, long beginVersion, long endVersion, LocalDateTime processingDateTime);

it throws Violation of PRIMARY KEY constraint 'PK__T_FLATTE__AFB35C3BAD604B4D'. Cannot insert duplicate key in object 'DBO.T_FLATTEN_PROCESSING_INFO'. The duplicate key value is (1001, 2001). This works for me in one sense. but my entire transaction is rolled back which I dont want. I need to capture exception, make some decision based on PK violation and proceed further.

org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only.

I am not sure where it is marked as Rollback-only

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I need
  • Whitelisted phrase (-1): works for me
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Sve
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Arul