{"record":{"id":"d74f5308137d6fdc","repo":"quarkusio/quarkus","slug":"id-was-invalidly-set-on-request-d74f53","errorCode":null,"errorMessage":"Id was invalidly set on request.","messagePattern":"Id was invalidly set on request\\.","errorType":"http","errorClass":"WebApplicationException","httpStatus":422,"severity":"error","filePath":"integration-tests/hibernate-orm-tenancy/connection-resolver-legacy-qualifiers/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java","lineNumber":91,"sourceCode":"    }\n\n    @POST\n    @Transactional\n    @Path(\"fruits\")\n    public Response createDefault(@NotNull Fruit fruit) {\n        return create(fruit);\n    }\n\n    @POST\n    @Transactional\n    @Path(\"{tenant}/fruits\")\n    public Response createTenant(@NotNull Fruit fruit) {\n        return create(fruit);\n    }\n\n    private Response create(@NotNull Fruit fruit) {\n        if (fruit.getId() != null) {\n            throw new WebApplicationException(\"Id was invalidly set on request.\", 422);\n        }\n        LOG.debugv(\"Create {0}\", fruit.getName());\n        entityManager.persist(fruit);\n        return Response.ok(fruit).status(201).build();\n    }\n\n    @PUT\n    @Path(\"fruits/{id}\")\n    @Transactional\n    public Fruit updateDefault(@PathParam(\"id\") int id, @NotNull Fruit fruit) {\n        return update(id, fruit);\n    }\n\n    @PUT\n    @Path(\"{tenant}/fruits/{id}\")\n    @Transactional\n    public Fruit updateTenant(@PathParam(\"id\") int id, @NotNull Fruit fruit) {\n        return update(id, fruit);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-tenancy/connection-resolver-legacy-qualifiers/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java#L73-L109","documentation":"FruitResource.create throws this WebApplicationException (HTTP 422) when the JSON body of a POST already contains an id. The resource generates identifiers via the database/EntityManager, so a client-supplied id would be silently ignored or cause a conflict; the endpoint rejects the request explicitly instead.","triggerScenarios":"POST to /fruits (or the tenant-scoped create endpoint) with a Fruit JSON body that includes a non-null \"id\" field.","commonSituations":"Clients round-trip an entity they previously fetched (e.g. GET then modify then POST instead of PUT), deserialization frameworks default id to 0 or a value, or copy-pasted payloads include the id.","solutions":["Remove the id field (or set it to null) from the JSON body before POSTing.","Use the PUT /fruits/{id} endpoint when updating an existing fruit instead of POST.","On the client, exclude the id from serialization for create requests (e.g. @JsonIgnore on write or a DTO without id)."],"exampleFix":"// before\nPOST /fruits\n{\"id\": 1, \"name\": \"Apple\"}\n// after\nPOST /fruits\n{\"name\": \"Apple\"}","handlingStrategy":"validation","validationCode":"if (fruit.getId() != null) {\n    throw new IllegalArgumentException(\"Do not send id on create; POST /fruits/{id} only for updates.\");\n}","typeGuard":"boolean isCreatable(io.quarkus.it.hibernate.multitenancy.fruit.Fruit f) {\n    return f != null && f.getId() == null && f.getName() != null;\n}","tryCatchPattern":"try {\n    Response r = target(\"/fruits\").request().post(Entity.json(fruit));\n    if (r.getStatus() == 422) { /* strip id and retry or surface error */ }\n} catch (WebApplicationException e) {\n    log.warn(\"Create rejected: \" + e.getMessage());\n}","preventionTips":["Never reuse a fetched entity object for POST bodies","Null out id before create calls","Use PUT for anything that has an id","Add client-side DTOs without id for create payloads"],"tags":["rest","validation","jpa","http-422"],"backgroundTag":"id-set-on-create-request","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}