{"record":{"id":"fb9d2ec99aa8a692","repo":"quarkusio/quarkus","slug":"id-was-invalidly-set-on-request-fb9d2e","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/datasource/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/datasource/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java#L73-L109","documentation":"Same as errorIndex 3950 but in the datasource-variant FruitResource: POST rejects a body whose id is already set with HTTP 422 because identifiers must be generated by the persistence layer, not supplied by clients.","triggerScenarios":"POST a Fruit JSON body containing a non-null \"id\" field to the datasource-based /fruits endpoint.","commonSituations":"Reusing a fetched entity object for create, client DTO defaults id, or POST used instead of PUT for updates.","solutions":["Omit the id (or null it) in the POST body.","Use PUT /fruits/{id} for updates.","Configure the client serializer to skip the id on create."],"exampleFix":"// before\n{\"id\": 7, \"name\": \"Cherry\"}\n// after\n{\"name\": \"Cherry\"}","handlingStrategy":"validation","validationCode":"if (fruit.getId() != null) {\n    fruit = new Fruit(fruit.getName()); // strip id before create\n}","typeGuard":"boolean isNewFruit(io.quarkus.it.hibernate.multitenancy.fruit.Fruit f) {\n    return f != null && f.getId() == null;\n}","tryCatchPattern":"try (Response r = target(\"/fruits\").request().post(Entity.json(fruit))) {\n    if (r.getStatus() == 422) { /* id was set; retry without id */ }\n}","preventionTips":["Separate Create DTO (no id) from Update DTO","Null out id before POST","Never POST an object previously returned by GET","Test create payloads against a schema that forbids id"],"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"}