menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Databases

>

Some Tips ...
source image

Dev

1w

read

21

img
dot

Image Credit: Dev

Some Tips on SQL Usage in Spring

  • 1. A Left Join followed by an Inner Join behaves like a regular Inner Join.
  • 2. Avoid using groupBy/associateBy in the app layer when pagination is applied to ensure consistency.
  • 3. Understand the SQL Query Execution Order: FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY.
  • 4. Adding AND conditions in LEFT JOIN ON does not affect row count.
  • 5. For one-to-one relationships, use '@OneToOne' and enforce a UNIQUE KEY in the database.
  • 6. '@Transactional' only guarantees atomicity in specific situations.
  • 7. WHERE vs HAVING: WHERE filters rows before grouping, while HAVING filters after grouping.
  • Consideration: Check and understand the actual SQL generated by JPA for better optimization.

Read Full Article

like

1 Like

For uninterrupted reading, download the app