I have a one-to-many
relationship with Customer
and Order
entity. This is of a composition relationship. I want to write a query to find out if there is a matching Order
with the given orderId
and the customerId
. This method should be in the CustomerRepository
@Query("select c from Customer c inner join c.orders o where c.id= ?1 and c.orders.")
Optional<Customer> findCustomerByOrderId(long orderId, long customerId);
I am interested in knowing, if the orderid belongs to the customer. What should be the query and should the method return a count or a boolean from the performance point of view.