Eclipse JNoSQL

Jakarta Query

One query language. Multiple persistence APIs. Different database capabilities.

Jakarta Query is a unifying specification that defines a common object-oriented query language for the Jakarta ecosystem. It is a language specification, not a Java query execution API: Jakarta Data and Jakarta NoSQL use it, and Eclipse JNoSQL executes the queries against your database.

The Jakarta Persistence Query Language (JPQL) has been widely used since 2006, but it is defined inside Jakarta Persistence. Jakarta Data 1.0 introduced the Jakarta Data Query Language (JDQL), a strict subset of JPQL intended for non-relational databases. Maintaining JPQL and JDQL separately became inconvenient, so Jakarta Query took over their evolution. It defines two levels: the persistence language, and the Jakarta Common Query Language (JCQL), a strict subset designed for Jakarta Data and Jakarta NoSQL providers on non-relational datastores. Developers rely on one query model instead of independently evolving languages.

One Specification, Two Language Levels

Jakarta Persistence Query Language (JPQL) Extended persistence language

Associations, joins, subqueries, grouping and advanced relational expressions.

Jakarta Common Query Language (JCQL) Common language subset

A portable foundation for multiple database technologies.

The Eclipse JNoSQL documentation focuses on JCQL.

One Query, Two APIs

The same JCQL query, FROM Product WHERE price < :max, used through two APIs.

Declarative repositories
@Query("FROM Product WHERE price < :max")
List<Product> affordable(
    @Param("max") BigDecimal max);
Jakarta NoSQLSince Jakarta NoSQL 1.1
Programmatic execution
List<Product> products = template
    .typedQuery("FROM Product WHERE price < :max",
                Product.class)
    .bind("max", max)
    .result();

Key Features

Query Portability & Limitations

One query language, different database capabilities.

  • Key-Value Access is primarily identifier-based, so arbitrary attribute filtering may be unavailable. Sorting, aggregation and conditional mutations are often restricted. Explore Key-Value model
  • Wide-Column Queries typically depend on partition keys, clustering columns and secondary indexes, which can restrict filtering and ordering. Scalar functions depend on the provider. Explore Wide-Column model
  • Document Attribute-based filtering is typically richer, and indexing affects what runs efficiently. Functions, scalar expressions and calculated updates vary by provider. Explore Document model
  • Graph Filtering is property-based, and scalar expressions vary by provider. Traversal and relationship-oriented operations may require specialized APIs. Explore Graph model
  • Time Series Time-oriented filtering and temporal queries are typical, but support varies. Updates and deletes may be restricted, and functions and scalar expressions depend on the provider. Explore Time Series model
  • Vector Filtering is typically on metadata, and arithmetic and scalar expressions may be restricted. Similarity search uses specialized vector APIs. Explore Vector model

Database Compatibility Reference

Explore supported functions, expressions and query operations for each database provider.

  • Supported
  • Restricted
  • Unsupported
View compatibility tables

Jakarta Common Query Language (JCQL)

JCQL is a textual query language. It is neither a repository API nor an annotation-based language, and it is not a type-safe Java API.

  • Common query concepts: a shared language rather than one dialect per specification.
  • Reusable query expressions: the same kind of expression can be used by Jakarta Data and Jakarta NoSQL.
  • Consistency: the persistence specifications build on the same query concepts.

Jakarta Query is a specification-level foundation, not an extra runtime service. Eclipse JNoSQL is the layer that executes queries against databases.

Relationship with Jakarta Data and Jakarta NoSQL

  • Jakarta Data defines repositories. Query strings written with @Query in a repository build on the shared query concepts.
  • Jakarta NoSQL defines mapping and templates for NoSQL databases. Since Jakarta NoSQL 1.1, Template.query and Template.typedQuery execute JCQL strings; see the Query API.
  • Eclipse JNoSQL implements the three specifications and translates supported queries to the underlying database.

The Fluent API of the Template is a Java API for query construction and is separate from the query language.

Using the Same Query in Both APIs

Both snippets in One Query, Two APIs assume a Product entity with a price attribute and omit imports. Parameters are bound by name: @Param in a Jakarta Data repository, and bind("max", max) on a Jakarta NoSQL query. typedQuery is used so that result() returns a List<Product> without an unchecked conversion. The Java API reference is in the Jakarta Data API documentation and the Jakarta NoSQL API documentation.

Portability Across APIs and Databases

Portability has three dimensions, and a common query language guarantees only the first.

Dimension Meaning
Language portability Consistent query syntax and semantics
API portability Query execution through Jakarta Data or Jakarta NoSQL
Execution capabilities Operations supported by the underlying database

A common language does not require every database technology to expose identical execution capabilities. Jakarta Query states that, for a non-relational database, support for conditional expressions, logical operators and arithmetic operators may differ from the language definition, and that a store which only looks up by key may support only an equality on the identifier. The Jakarta NoSQL specification states that a provider may reject operations the database cannot execute with an UnsupportedOperationException, and that scalar and time-based functions are generally evaluated by the database, so their behavior is not guaranteed.

Eclipse JNoSQL implements Jakarta Query while respecting these database-specific limitations. It does not claim that every JCQL feature runs on every database. The Query Portability & Limitations section summarizes typical limitations per database model, and Database Compatibility points to the per-provider reference.

Example Domain

The queries on this page use the Product entity from the Jakarta Data and Jakarta NoSQL guides, reduced here to its attributes. In JCQL, attribute names are the names of these persistent attributes.

@Entity
public class Product {

    @Id
    private String id;
    @Column
    private String name;
    @Column
    private String category;
    @Column
    private BigDecimal price;
    @Column
    private int stock;
    @Column
    private int minimumStock;
    @Column
    private LocalDate expirationDate;
}

Query Operations

A JCQL statement is a SELECT statement, an UPDATE statement or a DELETE statement. In the common language, a statement is made of the clauses below; there are no joins.

Clause Purpose Notes
SELECT Select attributes, ID(THIS) or COUNT(THIS) Optional; without it, queries return entities
FROM Identify the entity Optional in a select when the API supplies the entity; written as DELETE FROM in a delete
WHERE Filter entities Optional in all three statements
ORDER BY Define result ordering Select statements only
UPDATE Name the entity to modify Followed by SET
SET Define the updated attributes A comma-separated list of attribute = value
DELETE Remove matching entities Written DELETE FROM Entity

Eclipse JNoSQL parses the clauses of a select in the order SELECT, FROM, WHERE, ORDER BY. Keywords are case-insensitive; the examples write them in upper case.

Selecting entities

A query that has no SELECT clause returns whole entities. FROM names the entity and WHERE filters it:

FROM Product
FROM Product WHERE stock > 0

The entity is always the implicit variable THIS. It is not written as an alias, and SELECT THIS is not valid JCQL: to return the entity, omit the SELECT clause. When the API already knows the entity, such as a Jakarta Data repository or typedQuery("WHERE stock > 0", Product.class), the FROM clause can be omitted too.

Sorting

ORDER BY takes one or more attributes, or ID(THIS), each optionally followed by ASC or DESC. The default direction is ascending, and earlier items take precedence over later ones, which only break ties:

Form Meaning
ORDER BY name Ascending, by default
ORDER BY name ASC Ascending
ORDER BY price DESC Descending
ORDER BY price DESC, name ASC Descending price; name breaks ties
FROM Product
WHERE stock > 0
ORDER BY price DESC, name ASC
FROM Product ORDER BY ID(THIS)

Without ORDER BY the order is undefined. Sorting capabilities depend on the database: a database that cannot sort natively may reject the query or sort in Java, and the specification does not require either. Write ASC and DESC in upper case. The Eclipse JNoSQL parser accepts a lower-case desc but only recognizes the upper-case DESC, so a lower-case direction silently sorts in ascending order.

Updating entities

UPDATE names the entity, SET assigns a literal, a bound parameter or an expression to one or more attributes, and WHERE selects the entities to change. Use ID(THIS) to refer to the identifier, whatever the attribute is called in the class:

UPDATE Product
SET price = :price
WHERE ID(THIS) = :id
UPDATE Product
SET category = 'books', stock = 0
WHERE name = 'Java'

An attribute can be set to NULL with SET category = NULL. Without WHERE, every entity is updated. Calculated assignments such as stock = stock - 1 are covered in Calculated Updates.

Deleting entities

DELETE FROM Product
WHERE stock = 0

Without WHERE, DELETE FROM Product removes every Product. Conditional updates and deletes are not supported by every database; a Key-Value database, for example, generally works by identifier. See the compatibility reference.

Pagination and limits

JCQL has no LIMIT, OFFSET or SKIP clause. Limits and pagination are supplied by the API that executes the query:

API Mechanism Documentation
Jakarta Data Limit, PageRequest and @First method parameters or annotations Special Parameters, Pagination
Jakarta NoSQL skip and limit on the Fluent API Sorting and limits
Jakarta NoSQL Query and TypedQuery None. They only bind parameters and return results with result, stream and singleResult Query API

Textual LIMIT, SKIP and OFFSET are not a JNoSQL Specialization: the Eclipse JNoSQL parser rejects FROM Product LIMIT 10 and FROM Product SKIP 20 LIMIT 10 with a QueryException, in both the main and 1.x.x branches. This is a limit of the implementation as well as of JCQL, so the limit must come from the API that runs the query.

Standard Language and JNoSQL Specializations

JCQL is a common subset of the Jakarta Persistence query language (JPQL). Joins, aliases, GROUP BY, HAVING, DISTINCT, aggregate functions other than COUNT(THIS), NULLS FIRST, NULLS LAST and labels on selected items (AS) belong to the persistence language and are outside the common language. The Eclipse JNoSQL parser does not accept them either, nor SELECT *, SELECT THIS, !=, == and LIMIT.

Eclipse JNoSQL accepts a few forms that JCQL does not define. They are JNoSQL Specializations: they work with Eclipse JNoSQL, but a query that uses them is not portable to another Jakarta Query implementation.

Capability Standard JCQL JNoSQL support Example
Double-quoted strings Single quotes only Parsed as string literals WHERE name = "Keyboard"
Collection parameter in IN A parenthesized list Parsed; the bound collection supplies the items WHERE category IN :categories
Parameter as a LIKE pattern A string literal Parsed and bound at execution WHERE name LIKE :pattern

These forms were checked against the parser in the main and 1.x.x branches, where they behave the same. Parser acceptance does not guarantee execution: whether a database can evaluate the resulting condition is answered by the compatibility reference.

Parameters and Literals

Parameters keep the query definition separate from the values supplied at runtime, so the query text stays constant and values are never parsed as query text. Literals write a fixed value directly in the query.

Form Syntax Example
Named parameter : followed by an identifier :category
Positional parameter ? followed by an integer, numbered from ?1 ?1
String literal Text in single quotes 'Keyboard'
Integer literal Digits, optionally negative 10, -10
Decimal literal Digits with a decimal point 49.90
Boolean literal TRUE or FALSE TRUE
Null IS NULL, IS NOT NULL or SET attribute = NULL category IS NULL

Named and positional parameters

FROM Product
WHERE category = :category
AND price < :max
FROM Product
WHERE category = ?1
AND price < ?2

Positional parameters are numbered sequentially from ?1. A parameter may occur more than once in a query, and named and positional parameters must not be mixed in the same query. The Java side binds the values: Jakarta Data with @Query and @Param, and Jakarta NoSQL with bind.

Literals

FROM Product WHERE name = 'Keyboard'
FROM Product WHERE name = 'O''Brien'
FROM Product WHERE stock = 10
FROM Product WHERE price < 49.90
FROM Product WHERE active = TRUE
FROM Product WHERE category IS NULL
  • Strings use single quotes. A quote inside a string is written twice: 'O''Brien'.
  • Numbers without a decimal point are integers and numbers with one are decimals. The suffixes L, D and F and hexadecimal literals are not accepted by the Eclipse JNoSQL parser.
  • Booleans are the keywords TRUE and FALSE. The last example assumes a boolean active attribute, which Product does not declare.
  • Null is not a value in a comparison: category = NULL is invalid. Use IS NULL or IS NOT NULL to test, and NULL only as the new value in SET.
  • Dates and times have no literal syntax. The current date and time are written with LOCAL DATE, LOCAL TIME and LOCAL DATETIME; see Temporal Expressions. A quoted string is a string, not a date.

Eclipse JNoSQL also accepts double-quoted strings, which are not part of JCQL; use single quotes for portable queries.

Keywords and identifiers

  • Keywords such as FROM, WHERE and ORDER BY are case-insensitive. Avoid using a reserved word as an entity or attribute name, because that is not portable between providers.
  • Identifiers are case-sensitive: name and Name are different attributes.
  • Entity names follow the FROM clause. Eclipse JNoSQL resolves the name given to @Entity or the simple class name of the entity, such as Product.
  • Attribute names are persistent attributes of the entity in the FROM clause; there is no alias to qualify them.
  • Aliases are not part of JCQL. The entity is the implicit variable THIS, which appears only in ID(THIS) and COUNT(THIS). FROM Product p is rejected.

Conditional Expressions

Conditional expressions decide which entities match a query. They appear in the WHERE clause of SELECT, UPDATE and DELETE.

Operator or predicate Purpose Example
= Equality stock = 0
<> Inequality stock <> 0
> Greater than price > 100
>= Greater than or equal to price >= 100
< Less than price < 100
<= Less than or equal to price <= 100
BETWEEN Inclusive range price BETWEEN 100 AND 500
IN Membership in a list category IN ('audio', 'computing')
LIKE Pattern matching name LIKE 'Key%'
IS NULL Null comparison expirationDate IS NULL
IS NOT NULL Non-null comparison expirationDate IS NOT NULL

!= and == are not part of the language, and the Eclipse JNoSQL parser rejects them; write <> for inequality. Databases that cannot express a condition natively, such as a key-value store that only looks up the identifier, may reject it.

Comparisons

FROM Product WHERE stock = 0
FROM Product WHERE price >= 100
FROM Product WHERE stock <> 0

The remaining operators, >, < and <=, follow the same form. Both operands must have comparable types. Comparing two attributes is covered in Scalar Expressions.

Range and membership

FROM Product
WHERE price BETWEEN 100 AND 500

BETWEEN is inclusive: it matches prices greater than or equal to 100 and less than or equal to 500. NOT BETWEEN matches prices below 100 or above 500. The three operands must have the same type, and the bounds can be literals or parameters, such as BETWEEN :min AND :max.

FROM Product
WHERE category IN ('audio', 'computing')

IN matches when the attribute equals any item of the list. NOT IN matches the opposite. The left operand must be an attribute, and the items are literals or parameters of the same type, for example IN (:first, :second). A single collection parameter can be written as IN :categories, which is an Eclipse JNoSQL form that the common language does not define.

Databases generally require constant bounds and list items, so a literal or a bound parameter works best.

Null predicates

FROM Product WHERE expirationDate IS NULL
FROM Product WHERE expirationDate IS NOT NULL

Products without an expiration date match the first query, and the others match the second. The expression expirationDate = NULL is rejected; use IS NULL. Some databases distinguish an attribute stored as null from an attribute that is missing, and the two cases are not guaranteed to match alike on every database. A comparison with a null operand is never satisfied, so expirationDate <> :date does not match products without an expiration date.

Boolean expressions

Operator Result Precedence
NOT Satisfied when its operand is not satisfied Highest
AND Satisfied when both operands are satisfied Middle
OR Satisfied when at least one operand is satisfied Lowest

Comparisons and predicates bind tighter than all three, and parentheses override the order. AND is evaluated before OR, so these queries are different:

FROM Product
WHERE stock > 0
AND category = 'audio'
OR price < 100

This is read as (stock > 0 AND category = 'audio') OR price < 100. It returns the audio products in stock and also every product cheaper than 100, whether or not it is in stock.

FROM Product
WHERE stock > 0
AND (category = 'audio' OR price < 100)

Here the parentheses apply the stock condition to both alternatives. Only products in stock are returned.

Parentheses can be nested:

FROM Product
WHERE (stock > 0 AND (category = 'audio' OR category = 'computing'))
OR price < 20

NOT applies to the condition that follows it, and parentheses extend it to a group:

FROM Product WHERE NOT stock = 0
FROM Product WHERE NOT (stock = 0 OR price > 500)
FROM Product WHERE NOT category = 'audio' AND stock > 0

The last query applies NOT to category = 'audio' only. The meaning of NOT for a condition that involves null values is left to the implementation, so a negated condition on a nullable attribute should be checked against the target database.

Pattern matching

LIKE compares a string with a pattern. It is a wildcard match, not a regular expression.

Pattern element Matches
% Zero or more characters
_ Exactly one character
NOT LIKE Strings that do not match the pattern
ESCAPE 'c' Treats c%, c_ and cc in the pattern as a literal %, _ and c
FROM Product
WHERE name LIKE 'Key%'

Matches names that start with Key.

FROM Product
WHERE name LIKE '%board%'

Matches names that contain board anywhere.

FROM Product
WHERE name LIKE 'K_yboard'

Matches Keyboard, because _ stands for exactly one character.

FROM Product
WHERE name NOT LIKE 'Key%'
FROM Product
WHERE name LIKE '100!%%' ESCAPE '!'

The escape character is a single character. In the pattern, !% is a literal percent sign and the final % is a wildcard, so the query matches names that start with 100%, such as 100% Cotton. A quote inside a pattern is written as two single quotes.

The pattern is a string literal. Eclipse JNoSQL also accepts a parameter, as in LIKE :pattern, which the common language does not define. Native ESCAPE requires the pattern and the escape character to be available independently of stored data. Case sensitivity, collation and escaping rules depend on the database. See the compatibility reference.

Projections and Aggregation

A query returns complete entities unless a SELECT clause chooses what to retrieve instead. Selecting fewer attributes avoids loading data the caller does not need.

Selection form Query Result
Entity FROM Product Complete entities
One attribute SELECT name FROM Product The attribute values
Several attributes SELECT name, price FROM Product One value per selected attribute, for each entity
Identifier SELECT ID(THIS) FROM Product The identifiers
Count SELECT COUNT(THIS) FROM Product WHERE stock > 0 A single count
FROM Product
SELECT name FROM Product
SELECT name, price FROM Product
SELECT ID(THIS) FROM Product
SELECT COUNT(THIS)
FROM Product
WHERE stock > 0

A select clause takes either a list of attributes, a single ID(THIS) or a single COUNT(THIS); they cannot be combined, so SELECT category, COUNT(THIS) is invalid. COUNT(THIS) is the only aggregate function in the common language, and it needs a database that can count: it is not required for stores that only offer key-based lookups. GROUP BY, HAVING, DISTINCT, SUM, AVG, MIN and MAX belong to the persistence language and are not JCQL.

The selected values are mapped to Java types by the API that runs the query: a single attribute to its type, several attributes to a @Projection record, and COUNT(THIS) to a number. See Projections in the Jakarta NoSQL guide and @Query with projections in the Jakarta Data guide.

Standard Functions

The common language defines six standard functions. Function names are case-insensitive, and a call with the wrong number of arguments is rejected when the query is parsed. Functions such as TRIM or SQRT are not part of the common language.

Function Arguments Result
ABS(n) A numeric value Absolute value, in the same numeric type
LENGTH(s) A string Number of characters, as an integer
LOWER(s) A string The string in lowercase
UPPER(s) A string The string in uppercase
LEFT(s, n) A string and an integer The first n characters
RIGHT(s, n) A string and an integer The last n characters

Each function returns a value, so a call appears wherever a comparison accepts an operand.

FROM Product WHERE ABS(stock) > 10

ABS(stock) is the absolute value of the stock. The comparison matches products whose stock is more than 10 units away from zero in either direction, which is useful when stock can be negative because of backorders.

FROM Product WHERE LENGTH(name) > 20

Matches products whose name has more than 20 characters. How characters are counted, for example for accented or multi-byte text, can differ between databases.

FROM Product WHERE LOWER(name) = :name

Compares the lowercase form of the stored name with the bound value. The bound value must already be in lowercase for a match.

FROM Product WHERE UPPER(category) = 'AUDIO'

Matches the category regardless of the case in which it is stored.

FROM Product WHERE LEFT(name, 3) = 'USB'

LEFT(name, 3) is the first three characters of the name, so the query matches names that start with USB.

FROM Product WHERE RIGHT(name, 3) = 'Pro'

RIGHT(name, 3) is the last three characters of the name, so the query matches names that end with Pro.

Database-independent and database-dependent functions

Where a function runs depends on its arguments.

Characteristic Independent Database-dependent
Input Literal or bound parameter Stored attribute
Evaluation Eclipse JNoSQL, where supported Native database execution
Native function requirement Not necessarily required Required
Example name = UPPER(:name) UPPER(name) = :name

Independent evaluation. A function whose arguments are only literals, parameters or other such functions does not depend on stored data. Eclipse JNoSQL computes the value from the bound parameter, and the database receives an ordinary comparison value.

FROM Product WHERE name = UPPER(:name)

With :name bound to usb hub, the database receives a comparison against USB HUB.

Database-dependent evaluation. A function applied to a stored attribute can only be computed against the stored data, so the database must run it.

FROM Product WHERE UPPER(name) = :name

If the database cannot run the function natively, the operation fails with an UnsupportedOperationException instead of returning approximate results. The compatibility reference lists what each database supports.

Independent evaluation applies to values that are compared, not to every position of a query. The left side of an IN predicate, for example, must be an attribute path, and UPPER(name) IN ('A') is rejected.

Nested functions

The arguments of a function can be other functions.

FROM Product WHERE UPPER(LEFT(name, 3)) = 'USB'

The query matches products whose first three characters are USB, ignoring case. Because the innermost function reads a stored attribute, the whole expression is database-dependent and the database must support each function in it. Nesting does not make a function independent unless every argument is itself independent, as in UPPER(LEFT(:name, 3)).

Scalar Expressions

A scalar expression produces a single value that can take part in a comparison or an assignment. Operands are attributes, literals, parameters, functions or other scalar expressions.

Expression Example
Attribute reference stock
Addition stock + 10
Subtraction stock - minimumStock
Multiplication price * stock
Division price / 2
Unary expression -stock, +stock
Concatenation category || name
Function expression ABS(stock)
Parenthesized expression price * (stock + 10)

All of these forms are part of the common language and are accepted by Eclipse JNoSQL. Operators such as % and ^, and the CONCAT function, are not part of it. Whether a database can evaluate an expression over stored attributes is a separate question, answered by the compatibility reference.

Attribute-to-attribute comparisons

A comparison can have a stored attribute on both sides, so the database compares the two values without the application loading the entities.

FROM Product
WHERE stock < minimumStock

Returns the products whose stock is below their configured minimum, which is the list to replenish.

FROM Product
WHERE price > stock

Both attributes must have comparable types. Comparing two stored values requires the database to evaluate the expression against stored data, and a database without that capability rejects the query.

Arithmetic

Operator Meaning Example
+ Addition stock + 10
- Subtraction stock - minimumStock
* Multiplication price * stock
/ Division price / 2
- (unary) Negation -stock
+ (unary) Identity +stock
FROM Product
WHERE stock + 10 < minimumStock

Addition: for a replenishment of 10 units, matches products that would still be below their minimum stock after receiving them.

FROM Product
WHERE stock - minimumStock > 20

Subtraction: matches products holding more than 20 units above their minimum.

FROM Product
WHERE price * stock > 1000

Multiplication: matches products whose stock is worth more than 1000.

FROM Product
WHERE price / 2 < :max

Division: compares half of the price with a bound value.

FROM Product
WHERE -stock < -5

Both unary - and unary + apply to a numeric operand, and they bind tighter than any binary operator, so price * -stock means price * (-stock).

The operands of +, -, * and / must be numeric. The specification leaves the precise numeric behavior to the database and the Java type: precision, overflow, the treatment of integer division and the handling of null operands are not guaranteed to be identical across databases. An expression over a wrapper-typed attribute is null when an operand is null.

Precedence and parentheses

Binary operators are left-associative. From highest to lowest precedence:

Level Operators
1 Unary + and -
2 * and /
3 + and -
4 ||

Parentheses override this order.

FROM Product
WHERE price * stock + 10 > 1000

Without parentheses the multiplication runs first: the stock value plus 10.

FROM Product
WHERE price * (stock + 10) > 1000

With parentheses the addition runs first: the price multiplied by the stock plus 10 units.

These parentheses group scalar values. Grouping conditions with AND and OR is described in Boolean expressions.

String concatenation

The concatenation operator is ||. The language has no CONCAT function.

FROM Product
WHERE category || name = :value
FROM Product
WHERE category || ' - ' || name = :value

The second query joins the category, a separator and the name. Any number of operands can be chained, and an operand can be an attribute, a string literal, a bound parameter or a function such as UPPER. The operands must be strings, and the expression is a string. name || stock is not valid, even though the parser alone does not report it.

Concatenating stored attributes requires the database to compute the value. This is different from building a query string in Java: the operator runs inside the query, against stored data, and a bound parameter is never turned into query text.

Combining functions and expressions

Functions and operators nest. See Standard Functions for the functions themselves.

FROM Product
WHERE ABS(stock - minimumStock) > 10

Matches products whose stock is more than 10 units away from their target level, above or below.

FROM Product
WHERE LENGTH(name) * 2 > 40

Functions can also be operands of arithmetic. Each nested stored-value expression adds a requirement for the database.

Temporal Expressions

Temporal expressions refer to the current date or time, so the application does not need to build a literal value.

Expression Java temporal type
LOCAL DATE LocalDate
LOCAL TIME LocalTime
LOCAL DATETIME LocalDateTime

They are local values without a time zone, not instants. CURRENT_DATE, CURRENT_TIME and NOW are not part of the language.

FROM Product
WHERE expirationDate < LOCAL DATE

Returns the products whose expiration date is earlier than the current local date, that is, the expired products.

Product has no time-based attribute, so the next two examples use attributes of other entities.

FROM Shift
WHERE startTime < LOCAL TIME

Matches shifts whose LocalTime start time has already passed today.

FROM Event
WHERE endsAt < LOCAL DATETIME

Matches events whose LocalDateTime end has passed.

Resolution. The specification defines these expressions as the current value on the database server. Eclipse JNoSQL resolves them differently: it reads the clock of the application, in the default time zone of the JVM, before the query is sent, and the database receives an ordinary value. The database server clock and time zone are not consulted. One query uses a single instant for all its temporal expressions, so LOCAL DATE and LOCAL DATETIME in the same query never refer to different moments. Applications and database servers in different time zones can therefore disagree about what "today" means.

Compatibility. The compared attribute must be of the matching Java temporal type: a LocalDate attribute with LOCAL DATE, a LocalTime attribute with LOCAL TIME and a LocalDateTime attribute with LOCAL DATETIME. The comparison itself is executed by the database against the stored values, and the way temporal values are stored depends on the provider.

Calculated Updates

A fixed-value update assigns a literal or a bound value. A calculated update computes the new value from the stored one.

Form Example Needs native execution
Fixed value SET stock = :stock No
Arithmetic on the stored value SET stock = stock - 1 Yes
Function on the stored value SET name = UPPER(name) Yes
Concatenation with the stored value SET name = name || '!' Yes
UPDATE Product
SET stock = :stock
WHERE id = :id
UPDATE Product
SET stock = stock - 1
WHERE id = :id

Attributes are referenced by name in SET and WHERE; id names the identifier attribute, and ID(THIS) is the equivalent explicit form. The calculated form is executed by the database against the stored value, instead of the application reading the entity, changing it and saving it.

UPDATE Product
SET stock = stock - 1
WHERE id = :id AND stock > 0

The extra condition prevents the decrement when no stock remains, so the stock never becomes negative.

UPDATE Product
SET price = price * :factor
WHERE category = :category

With :factor bound to 1.1, every product of the category receives a 10% price increase.

UPDATE Product
SET name = UPPER(name)
WHERE category = :category

Functions are accepted in assignments, so the names of the matching products are converted to uppercase.

UPDATE Product
SET stock = stock - 1, minimumStock = minimumStock + 1
WHERE id = :id

A SET clause can hold several comma-separated assignments. The order in which assignments that read attributes changed by the same update are applied is not defined, and support for several calculated assignments depends on the provider.

Execution and guarantees. Native execution avoids an application-level read-modify-write sequence, but atomicity, transactions and concurrency behavior are those of the underlying database and are not guaranteed to be the same everywhere. A calculated update is not described as atomic or concurrency-safe by the language.

Unsupported updates. When a database cannot compute an assignment, the update is rejected with an UnsupportedOperationException before any entity is changed. There is no fallback that loads entities and modifies them in Java. An assignment with only literals, parameters or functions of them, such as SET name = UPPER(:name), does not depend on stored data and is evaluated by Eclipse JNoSQL. The compatibility reference lists which databases support calculated updates.

Database Compatibility

Query execution respects the capabilities of the underlying database. Before relying on a feature, check that the selected provider supports it, especially for:

  • Conditional queries, sorting and projections.
  • Standard functions.
  • Attribute-to-attribute comparisons and arithmetic expressions.
  • String concatenation and LIKE with ESCAPE.
  • Calculated updates and conditional mutations (UPDATE and DELETE with a WHERE clause).

Functions applied only to literals or parameters, such as UPPER(:name), are evaluated by Eclipse JNoSQL, while functions applied to stored attributes, such as UPPER(name), need native database support. See Database-independent and database-dependent functions. An operation that the database cannot execute is rejected, typically with an UnsupportedOperationException, and is not retried by loading and filtering entities in Java.

The Database Compatibility Reference in JNoSQL Databases is the authoritative per-provider source. Its legend defines five states: supported (✅), supported with restrictions (⚠️), unsupported (❌), not applicable (—) and not verified (?). A ❌ for an operation such as DELETE refers to the native expression form, not to ordinary CRUD. For the typical limitations of each database model, see Query Portability & Limitations.

Availability

Jakarta Query 1.0, Jakarta Data 1.1 and Jakarta NoSQL 1.1 are still under development: Jakarta Data and Jakarta NoSQL 1.1 are published as milestones (1.1.0-M4) and no Jakarta Query API artifact has been released. The JCQL features on this page were checked against the Eclipse JNoSQL development branch. The classes behind temporal expressions and native function handling are not present in Eclipse JNoSQL 1.2.0, 1.2.0-M2 or 2.0.0-M1, so use a build from the development branch to try them. See the version note in the Jakarta NoSQL guide.

References