0

I've got a problem with my Spring-Boot Application. I'm trying to send a notification after i get a result from my function with @Transactional, but @Transactional doesn't work, the rollback doesn't work. This is the code.

@Service
public class ParkingServiceImpl implements ParkingService {

   @Override
   public void getParkingFromBOAsyncWrapper() {
         ArrayList<BOUserParking> listUserParkingfromBO = getParkingFromBOTransaction();

        /** Send notification **/
        if(listUserParkingfromBO!=null){
             notificationService.sendNotification(listUserParkingfromBO);
        }
   }


   @Transactional
   @Override
   public ArrayList<BOUserParking> getParkingFromBOTransaction() {
              // .... insert or update on db
   }
}

2 Answers2

3

Transactional will not work if called within the same class. Transactional (and similar e.g. Async) works via creating proxies between the calling classes. You must call it from another class to get the transactional functionality.

I would move your DAO calls to a RespositoryService that handles the transactionallity.

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54
0

Put @Transactional annotation inside DAO class method, not in class.

Alien
  • 15,141
  • 6
  • 37
  • 57