JPA-SQL

JPA-SQL documentation

Search this documentation

Popular Topics

No labels match these criteria.



Featured Pages

Filter by label

There are no items with the selected labels at this time.

Recently Updated Pages

About JPA-SQL

JPA-SQL is a domain-specific, database-independent language (DSL). The syntax is deliberately similar to SQL so that JPA-SQL is easy to learn. However, JPA-SQL is not to be confused with native SQL. Queries formulated in JPA-SQL are never sent to a database. Instead, they are converted to Java code based on the JPA Criteria API. Thus, you can access all the benefits of the JPA Criteria API without having to write the JPA Criteria code.

At runtime, the JPA provider generates the native SQL statements from the generated JPA Criteria code to match the connected database, and these are sent to the database. Thus JPA-SQL combines the simplicity of SQL with the numerous advantages of JPA Criteria API.

JPQL and native SQL

Many JPA developers use JPQL instead of JPA Criteria API, because JPQL code is much clearlier than Criteria code. JPA allows us to use native SQL as well. However, JPQL contains SQL strings, which have lots of disadvantages.

Benefits with JPA-SQL compared to JPQL and native SQL

  • Clearer code structure
  • Type safe
  • Any order of statements
  • IDE support
    • Code Completion - detection of keywords, operators, and entities
    • Syntax highlighting
    • Code folding
    • Formatter

    • Inline refactoring and refactoring participants for JDT member renames and moves

    • Hovers

    • Linking (Ctrl+Click)

    • Outline view

    • Error/warning markers with quick fixes

    • Code templates

    • Integration in Eclipse build process

    • Debuggable (JPA Criteria Code is generated)
  • Query method is automatically generated in DAO
  • Database independent

Benefits with JPA-SQL compared to JPA Criteria API

Why not using JPA Criteria API directly?

  • SQL-like syntax and code structure
  • Significantly lower complexity
  • Cleaner code
  • Easy to learn