0

enter image description here

I am developing a food ordering application, As shown in the image user1 will make payment and order then call API /waitForStatus/orderid To get the confirmation of it, which should return only after Payment Provider confirms back to us.

Payment Provider will update the table as Rejected or Confirmed using API /confirmOrder/orderid

My question is how to add a listener to a specific row and column.To know when provider updates back status

Here is my Entity Class

@Data
@Entity
@Table(name = "Order")
public class Order{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    
    @Column(name = "STATUS")
    private String status;
}

Here is my JPA Repository class

@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {

    Order getOrderById(Long id);

}

Here is my Service class

@Service
public class OrderDomainService implements IOrderDomainService {
    private final OrderRepository orderRepository;

    public OrderDomainService(OrderRepository orderRepository) {
        this.orderRepository = orderRepository;
    }

   @Override
   public UserOrder getOrderById(Long orderId) {
         return orderRepository.getOrderById(Long id)
   }
   
   @Override
   public UserOrder waitForStatusCongfirmation(Long orderId) {
        
        //<-------------How to handle here
   }

}

Let me know how to listen for a change in specific row, Thank You.

3
  • 1
    Just google hibernate entity listeners Commented Feb 19, 2021 at 14:58
  • You can't listen for database changes. You have to use a task scheduler like Quartz to periodically check for whichever Ids are on queue. There is no mechanism by which the database can ever notify the application for changes like that. Commented Feb 19, 2021 at 21:40
  • 1
    I think this must be done on the application level. If you want to do it synchronously, and by that I mean you are "blocking" user by having to wait for a reply from PaymentProvider then something like periodically checking the database can be one solution as a proposition from @coladict If you want to do it async, then maybe you can you just send a push notification to a user to let him/her know that the payment was successful. Commented Feb 20, 2021 at 11:20

1 Answer 1

1

There is a great tool called Debezium that you can use to listen for any database changes: https://debezium.io/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.