{"record":{"id":"88b89c8a9960dedf","repo":"quarkusio/quarkus","slug":"query-string-cannot-be-empty","errorCode":null,"errorMessage":"Query string cannot be empty","messagePattern":"Query string cannot be empty","errorType":"exception","errorClass":"PanacheQueryException","httpStatus":null,"severity":"error","filePath":"extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java","lineNumber":117,"sourceCode":"        }\n        if (trimmedForAnalysis.startsWith(\"order by \")) {\n            // ignore it\n            return \"FROM \" + getEntityName(entityClass);\n        }\n        if (trimmedForAnalysis.indexOf(' ') == -1 && trimmedForAnalysis.indexOf('=') == -1 && paramCount == 1) {\n            query += \" = ?1\";\n        }\n        return \"FROM \" + getEntityName(entityClass) + \" WHERE \" + query;\n    }\n\n    public static String createUpdateQuery(Class<?> entityClass, String query, int paramCount) {\n        if (query == null) {\n            throw new PanacheQueryException(\"Query string cannot be null\");\n        }\n\n        String trimmedForAnalysis = trimForAnalysis(query);\n        if (trimmedForAnalysis.isEmpty()) {\n            throw new PanacheQueryException(\"Query string cannot be empty\");\n        }\n\n        // backwards compat trying to be helpful, remove the from\n        if (trimmedForAnalysis.startsWith(\"update from\")) {\n            // find the original from and skip it\n            int index = query.toLowerCase(Locale.ROOT).indexOf(\"from\");\n            return \"update \" + query.substring(index + 4);\n        }\n        if (trimmedForAnalysis.startsWith(\"update \")) {\n            return query;\n        }\n        if (trimmedForAnalysis.startsWith(\"from \")) {\n            // find the original from and skip it\n            int index = query.toLowerCase(Locale.ROOT).indexOf(\"from\");\n            return \"UPDATE \" + query.substring(index + 4);\n        }\n        if (trimmedForAnalysis.indexOf(' ') == -1 && trimmedForAnalysis.indexOf('=') == -1 && paramCount == 1) {\n            query += \" = ?1\";","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/panache-hibernate-common/runtime/src/main/java/io/quarkus/panache/hibernate/common/runtime/PanacheJpaUtil.java#L99-L135","documentation":"PanacheJpaUtil.createUpdateQuery validates the query string passed to Panache update operations (`PanacheEntity.update(...)` / `PanacheRepository.update(...)`). A null query raises 'cannot be null' and a query that is empty or only whitespace raises 'Query string cannot be empty'. Panache requires a non-empty JPQL/HQL update statement because it delegates parsing (removing a leading 'update from' for backwards compatibility) to build the actual update query.","triggerScenarios":"Calling PanacheEntityManager.update(...), PanacheEntity.update(...) or PanacheRepository.update(...) with an empty string, a string of only spaces/newlines, or a variable that resolved to an empty value (e.g. an empty config property or concatenated fragments that produced nothing).","commonSituations":"Dynamically building update statements from user input or configuration where the query fragment ends up empty; typo'd variable initialization; framework wrappers that pass through blank queries; migrating code where a condition made the query string empty.","solutions":["Ensure the string passed to update(...) is a complete non-empty JPQL/HQL statement, e.g. \"name = :name where id = :id\"","Trim/validate the query before calling update, and guard blank values from config/user input","If the query is built dynamically, throw your own descriptive exception when the fragment list is empty instead of letting Panache fail","Remember Panache allows omitting 'update Entity' / 'update from Entity'; pass only 'set ... [where ...]' content if using the shorthand, but never an empty string"],"exampleFix":"// before\nString query = buildUpdateFragment(params); // may return \"\"\nrepo.update(query);\n\n// after\nString query = buildUpdateFragment(params);\nif (query == null || query.isBlank()) {\n    throw new IllegalArgumentException(\"No update criteria provided\");\n}\nrepo.update(query);","handlingStrategy":"validation","validationCode":"if (query == null || query.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"update query must be a non-empty JPQL fragment\");\n}\nrepository.update(query);","typeGuard":"boolean isValidUpdateQuery(String q) {\n    return q != null && !q.trim().isEmpty();\n}","tryCatchPattern":"try {\n    repo.update(query);\n} catch (PanacheQueryException e) {\n    log.error(\"Invalid update query supplied: '{}'\", query, e);\n    throw new IllegalStateException(\"Check update statement construction\", e);\n}","preventionTips":["Validate dynamically built queries before passing them to update(...)","Never pass raw config values straight into update without a blank check","Unit-test query builders with edge cases (empty fragment lists)","Remember Panache accepts 'set ... where ...' fragments — pass meaningful content, never \"\""],"tags":["panache","jpa","validation","query"],"backgroundTag":"empty-query-string","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}