I have a query that joins two tables (events and event_properties):
SELECT e.*, ep.*
FROM event e
JOIN event_properties ep
ON e.event_properties_id = ep.id
WHERE e.status = 0
In my R2DBC repository
@Query("""
SELECT e.*, ep.*
FROM event e
JOIN event_properties ep
ON e.event_properties_id = ep.id
WHERE e.status = 0
""")
Flux<EventWithProperties> findAllByGeneralEventIds(List<Long> eventTypeId);
I understand that in JPA, this same JOIN query might still cause N+1 problems due to lazy loading, requiring JOIN FETCH. However, I'm told that in R2DBC, the regular JOIN is sufficient to prevent N+1 queries. Questions:
1. Why doesn't R2DBC suffer from the N+1 problem with a simple JOIN while JPA does?
2. Is there any scenario where R2DBC might still have N+1 issues?
I'd appreciate detailed explanations about the architectural differences between R2DBC and JPA that cause this different behavior.