quarkusio/quarkus · error · PanacheQueryException

Query string cannot be null

Error message

Query string cannot be null

What it means

PanacheJpaUtil.createUpdateQuery translates Panache update calls (e.g. update("name = ?1", params)) into JPQL. A null query string cannot be interpreted — neither HQL nor a simple update fragment — so it throws PanacheQueryException before any analysis.

Source

Thrown at extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java:112

                || trimmedForAnalysis.startsWith("from ")) {
            return query;
        }
        if (trimmedForAnalysis.startsWith("where ")) {
            return "FROM " + getEntityName(entityClass) + " " + query;
        }
        if (trimmedForAnalysis.startsWith("order by ")) {
            // ignore it
            return "FROM " + getEntityName(entityClass);
        }
        if (trimmedForAnalysis.indexOf(' ') == -1 && trimmedForAnalysis.indexOf('=') == -1 && paramCount == 1) {
            query += " = ?1";
        }
        return "FROM " + getEntityName(entityClass) + " WHERE " + query;
    }

    public static String createUpdateQuery(Class<?> entityClass, String query, int paramCount) {
        if (query == null) {
            throw new PanacheQueryException("Query string cannot be null");
        }

        String trimmedForAnalysis = trimForAnalysis(query);
        if (trimmedForAnalysis.isEmpty()) {
            throw new PanacheQueryException("Query string cannot be empty");
        }

        // backwards compat trying to be helpful, remove the from
        if (trimmedForAnalysis.startsWith("update from")) {
            // find the original from and skip it
            int index = query.toLowerCase(Locale.ROOT).indexOf("from");
            return "update " + query.substring(index + 4);
        }
        if (trimmedForAnalysis.startsWith("update ")) {
            return query;
        }
        if (trimmedForAnalysis.startsWith("from ")) {
            // find the original from and skip it

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a non-null query string, e.g. update("name = :name", params) or update("from Person where name = :name").
  2. Null-check/require the query at your API boundary: Objects.requireNonNull(query).
  3. If you intended to update the whole entity, use entity persist/merge APIs instead of an update query.

Example fix

// before
String q = condition != null ? "name = :name" : null;
personRepo.update(q, params); // NPE-style failure
// after
if (q != null) { personRepo.update(q, params); } else { /* handle empty update */ }
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(query, "query must not be null");
personRepo.update(query, params);

Type guard

String requireQuery(String q) {
    if (q == null || q.isBlank()) throw new IllegalArgumentException("query required");
    return q;
}

Try / catch

try {
    PanacheJpaUtil.createUpdateQuery(entityClass, query, paramCount);
} catch (PanacheQueryException e) {
    // handle null/empty query: use default query or surface client error
}

Prevention

When it happens

Trigger: Calling PanacheEntity.update(null, ...) / repository.update(null, ...) or a delete/update helper that forwards a null query, e.g. passing a variable that failed to initialize.

Common situations: Passing an unset String variable or a null result of a builder/optional chain; calling update() with no query where an overload without query was expected; refactoring that dropped the literal query.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1a4b8856f37f908c. Report an issue: GitHub.