{"record":{"id":"76b7515a39b0649e","repo":"quarkusio/quarkus","slug":"fruit-with-id-of-id-does-not-exist-76b751","errorCode":null,"errorMessage":"Fruit with id of ${id} does not exist.","messagePattern":"Fruit with id of (.+?) does not exist\\.","errorType":"http","errorClass":"WebApplicationException","httpStatus":404,"severity":"error","filePath":"integration-tests/hibernate-search-orm-elasticsearch-tenancy/src/main/java/io/quarkus/it/hibernate/search/orm/elasticsearch/multitenancy/fruit/FruitResource.java","lineNumber":52,"sourceCode":"    EntityManager entityManager;\n    @Inject\n    SearchSession searchSession;\n\n    @GET\n    @Path(\"/\")\n    @Transactional\n    public Fruit[] getAll() {\n        return entityManager.createNamedQuery(\"Fruits.findAll\", Fruit.class)\n                .getResultList().toArray(new Fruit[0]);\n    }\n\n    @GET\n    @Path(\"/{id}\")\n    @Transactional\n    public 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    @Path(\"/\")\n    @Transactional\n    public 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(Response.Status.CREATED).build();\n    }\n\n    @PUT\n    @Path(\"/{id}\")","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-search-orm-elasticsearch-tenancy/src/main/java/io/quarkus/it/hibernate/search/orm/elasticsearch/multitenancy/fruit/FruitResource.java#L34-L70","documentation":"Thrown by the public findById endpoint of the Hibernate Search Elasticsearch tenancy FruitResource when entityManager.find(Fruit.class, id) finds no Fruit for the given id in the current tenant. It is a JAX-RS WebApplicationException mapped to HTTP 404. Unlike the schema-based sample, this is the public resource method itself, executed within @Transactional so the session/tenant context is active.","triggerScenarios":"GET /fruits/{id} on the hibernate-search-orm-elasticsearch-tenancy application with an id that does not exist in the active tenant, whether deleted, never created, or belonging to another tenant's index/schema.","commonSituations":"Id created under tenant A but fetched under tenant B (Search index and DB both tenant-filtered); Elasticsearch indexing lag is irrelevant here since the lookup uses the ORM, but missing DB seed data triggers it; stale ids across test lifecycle methods.","solutions":["Fetch with the same tenant header used at creation time","Verify existence first via GET or the search endpoint, or catch the 404 client-side","Seed the fruit for the tenant under test before requesting it","Create the fruit with POST /fruits and use the returned id"],"exampleFix":"// before\ngiven().header(\"tenantId\", \"tenant-b\").get(\"/fruits/\" + idCreatedForTenantA) // 404\n// after\ngiven().header(\"tenantId\", \"tenant-a\").get(\"/fruits/\" + idCreatedForTenantA) // 200","handlingStrategy":"try-catch","validationCode":"if (given().header(\"tenantId\", tenant).get(\"/fruits/\" + id).getStatusCode() == 404) {\n    throw new SkipException(\"No fruit \" + id + \" for tenant \" + tenant);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Fruit f = given().header(\"tenantId\", tenant).get(\"/fruits/\" + id).then()\n        .statusCode(200).extract().as(Fruit.class);\n} catch (AssertionError notFound) {\n    // 404: handle missing entity for this tenant\n}","preventionTips":["Pair create and read calls with the same tenant header","Seed fruits per tenant before lookup-based tests","Capture ids from creation responses rather than constants","Remember entity lookups go through ORM with tenant filter, not the Elasticsearch index"],"tags":["rest","jaxrs","http-404","hibernate-search","multitenancy"],"backgroundTag":"rest-resource-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"}