{"record":{"id":"31be861e00e6e326","repo":"quarkusio/quarkus","slug":"fruit-with-id-of-id-does-not-exist-31be86","errorCode":null,"errorMessage":"Fruit with id of \" + id + \" does not exist.","messagePattern":"Fruit with id of \" \\+ id \\+ \" does not exist\\.","errorType":"http","errorClass":"WebApplicationException","httpStatus":404,"severity":"error","filePath":"integration-tests/hibernate-orm-tenancy/datasource/src/main/java/io/quarkus/it/hibernate/multitenancy/fruit/FruitResource.java","lineNumber":70,"sourceCode":"                .getResultList().toArray(new Fruit[0]);\n    }\n\n    @GET\n    @Path(\"fruits/{id}\")\n    public Fruit getSingleDefault(@PathParam(\"id\") int id) {\n        return findById(id);\n    }\n\n    @GET\n    @Path(\"{tenant}/fruits/{id}\")\n    public Fruit getSingleTenant(@PathParam(\"id\") int id) {\n        return findById(id);\n    }\n\n    private Fruit findById(int id) {\n        Fruit entity = entityManager.find(Fruit.class, id);\n        if (entity == null) {\n            throw new WebApplicationException(\"Fruit with id of \" + id + \" does not exist.\", 404);\n        }\n        return entity;\n    }\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","sourceCodeStart":52,"sourceCodeEnd":88,"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#L52-L88","documentation":"FruitResource.findById (datasource variant) throws this WebApplicationException (HTTP 404) when entityManager.find(Fruit.class, id) returns null, meaning no Fruit with that id exists in the database visible to the current tenant.","triggerScenarios":"GET /fruits/{id} with an id that has no row, or a row that belongs to a different tenant than the one selected by the request's tenant identifier.","commonSituations":"Wrong tenant header/datasource so the row is in another schema, entity deleted concurrently, stale bookmarked URL, or off-by-one/auto-increment gap ids.","solutions":["Confirm the id via the list endpoint GET /fruits before fetching by id.","Ensure the tenant identifier matches the tenant owning the row.","Handle 404 in the client as 'not found' and do not retry.","Create the entity if it should exist."],"exampleFix":"// before\nGET /fruits/999   // 404\n// after\nGET /fruits/1     // use an id that exists for the current tenant","handlingStrategy":"try-catch","validationCode":"List<Integer> ids = target(\"/fruits\").request().get(new GenericType<List<Fruit>>(){})\n        .stream().map(Fruit::getId).collect(Collectors.toList());\nif (!ids.contains(id)) { throw new IllegalStateException(\"Fruit \" + id + \" not found\"); }","typeGuard":null,"tryCatchPattern":"try {\n    return target(\"/fruits/\" + id).request().get(Fruit.class);\n} catch (WebApplicationException e) {\n    if (e.getResponse().getStatus() == 404) { return Optional.empty(); }\n    throw e;\n}","preventionTips":["Verify tenant header before cross-tenant lookups","Use Optional/empty handling for possibly-missing entities","Avoid hardcoding ids in tests; query them first","Handle auto-increment gaps; never assume consecutive ids"],"tags":["rest","jpa","http-404","multitenancy"],"backgroundTag":"entity-not-found","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"}