I have a database relation which looks like this (in reality it looks slightly different but I removed unimportant fields):
Table Customer (
ID NUMBER(13),
...
)
Table Orders (
ID NUMBER(13),
BUYER_ID NUMBER(13),
SELLER_ID NUMBER(13),
...
)
Both BUYER_ID and SELLER_ID are references to CUSTOMER table. And in my situation there are cases that BUYER_ID and SELLER_ID might be the same for an order (I know it sounds funny).
My question is: if I am asking for a specific order using jpa repository, with both buyer and seller being the same customer, is this query optimized to return the same object? Or is the customer table asked twice for the same object?
The background of this question is that my team wants to add a flag in order table which would indicate weather the buyer and seller are the same (to optimize the query) but I believe that this is already optimized with springboot. Unfortunately I cannot find confirmation for this anywhere :(