quarkusio/quarkus · error · WebApplicationException
Id was invalidly set on request.
Error message
Id was invalidly set on request.
What it means
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.
Source
Thrown at integration-tests/hibernate-orm-tenancy/connection-resolver-legacy-qualifiers/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java:91
}
@POST
@Transactional
@Path("fruits")
public Response createDefault(@NotNull Fruit fruit) {
return create(fruit);
}
@POST
@Transactional
@Path("{tenant}/fruits")
public Response createTenant(@NotNull Fruit fruit) {
return create(fruit);
}
private Response create(@NotNull Fruit fruit) {
if (fruit.getId() != null) {
throw new WebApplicationException("Id was invalidly set on request.", 422);
}
LOG.debugv("Create {0}", fruit.getName());
entityManager.persist(fruit);
return Response.ok(fruit).status(201).build();
}
@PUT
@Path("fruits/{id}")
@Transactional
public Fruit updateDefault(@PathParam("id") int id, @NotNull Fruit fruit) {
return update(id, fruit);
}
@PUT
@Path("{tenant}/fruits/{id}")
@Transactional
public Fruit updateTenant(@PathParam("id") int id, @NotNull Fruit fruit) {
return update(id, fruit);View on GitHub (pinned to e1c734241f)
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).
Example fix
// before
POST /fruits
{"id": 1, "name": "Apple"}
// after
POST /fruits
{"name": "Apple"} Defensive patterns
Strategy: validation
Validate before calling
if (fruit.getId() != null) {
throw new IllegalArgumentException("Do not send id on create; POST /fruits/{id} only for updates.");
} Type guard
boolean isCreatable(io.quarkus.it.hibernate.multitenancy.fruit.Fruit f) {
return f != null && f.getId() == null && f.getName() != null;
} Try / catch
try {
Response r = target("/fruits").request().post(Entity.json(fruit));
if (r.getStatus() == 422) { /* strip id and retry or surface error */ }
} catch (WebApplicationException e) {
log.warn("Create rejected: " + e.getMessage());
} Prevention
- 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
When it happens
Trigger: POST to /fruits (or the tenant-scoped create endpoint) with a Fruit JSON body that includes a non-null "id" field.
Common situations: 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.
Related errors
- Fruit Name was not set on request.
- Id was invalidly set on request.
- Fruit Name was not set on request.
- Id was invalidly set on request.
- Id was invalidly set on request.
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/d74f5308137d6fdc.
Report an issue: GitHub.