What is the naming convention for dynamic queries in JPA?

The Java Persistence API (JPA) generates SQL query statements based on method names in dynamic queries. Here are common naming rules for JPA dynamic queries:

  1. Choose to search (Select)
  2. Find entities by + property name: Search for entities based on a specified property and return a list of entities that meet the criteria.
  3. Find the first entity that meets the specified condition by the attribute name.
  4. findTopBy + attribute name: search based on the specified attribute and return the first entity that meets the criteria.
  5. Query conditions (Where)
  6. Find by + property name + condition expression: search for entities based on specified property and condition, returning a list of entities that meet the criteria.
  7. findBy + property name + property name + condition expression: Search for entities based on multiple specified properties and conditions, returning a list of entities that meet the criteria.
  8. Sort query
  9. Search and order entities by a specified attribute.
  10. Pagination查询
  11. Find by + attribute name + Pageable: Perform a paginated query based on a specific attribute and return a paginated list of entities that meet the conditions.
  12. Aggregation Query
  13. Count by + property name: The number of entities that meet the criteria is calculated based on the specified property.
  14. sumBy + property name: Calculate the sum of entity properties based on the specified attribute and return the total sum of properties that meet the condition.

The above are common rules for JPA dynamic query naming conventions, which can be used to generate SQL query statements based on actual requirements.

bannerAds