The JPA-SQL editor is a powerful tool that facilitates the formulation of your database queries in RapidClipse. 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, Hibernate 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.

Benefits of JPA-SQL compared to the use of SQL strings:

  • 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 of JPA-SQL in comparison to the JPA Criteria API:

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

  1. Under Project Management > Data Access click the DAO with which you want to perform a database query, e.g.
  2. Press Strg + Space and select query: create new query in the following autocomplete window.
  3. Enter an appropriate method name for the generated method, e.g. findAllCustomer.

  4. After the keyword from, enter C, press Strg + Space and select Customer.
  5. Click Save.

  • Queries - JPA-SQL code.

  • Java - Generated Java code based on JPA Criteria API. The necessary imports are generated based on the query method. 

  • Find all 

    Alternative spelling:

  • Where condition

  • Where condition with parameter

    It is also possible to pass objects as parameters:

  • Like operator

  • Concat function

  • Returns specific columns

  • Saves the query result in a different class

  • Alias

  • Logical AND

  • Logical OR

  • MAX function - Returns the highest unit price

  • MIN function - Returns the lowest unit price

  • AVG function - Grouped by product name. Calculates the average order price of the orders within a group of products

  • ORDER BY function 

    • Descending order

    • Ascending order

  • Count function

  • Subselects

    Alternative to Subselects:

  • Complex queries
    • Returns all orders from London grouped by the sum of those orders

    • Possible short form

  • JPA-SQL functions - JPA-SQL has been developed to simplify the use of the JPA Criteria API. The range of JPA-SQL functions is limited by the range of the JPA Criteria API functions.
  • Edit generated code - The generation of the Java JPA Criteria codes is unidirectional. This means that changes are possible only in the JPA-SQL code. The generated Java JPA Criteria code cannot be edited.
  • Multiple query methods - Any number of query methods can be located in a DAO class.

JPA-SQL Language Specification