{"record":{"id":"ec3ffd9ac70585c1","repo":"quarkusio/quarkus","slug":"entity-s-was-not-found-did-you-forget-to-annot","errorCode":null,"errorMessage":"Entity '%s' was not found. Did you forget to annotate your Panache Entity classes with '@Entity'?","messagePattern":"Entity '(.+?)' was not found\\. Did you forget to annotate your Panache Entity classes with '@Entity'\\?","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java","lineNumber":119,"sourceCode":"     *\n     * @return {@link Session}\n     */\n    public SessionType getSession(Class<?> clazz) {\n        String clazzName = clazz.getName();\n        String persistentUnitName = entityToPersistenceUnit.get(clazzName);\n        if (persistentUnitName == null) {\n            if (entityToPersistenceUnitIsIncomplete == null || entityToPersistenceUnitIsIncomplete) {\n                // When using persistence.xml, `entityToPersistenceUnit` is most likely empty,\n                // so we'll just return the default PU and hope for the best.\n                // The error will be thrown later by Hibernate ORM if necessary;\n                // it will be a bit less clear, but this is an edge case.\n                SessionType session = getSession(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME);\n                if (session != null) {\n                    return session;\n                }\n            }\n            // For Quarkus-configured PUs, or if there is no PU, this is definitely an error.\n            throw new IllegalStateException(String.format(\n                    \"Entity '%s' was not found. Did you forget to annotate your Panache Entity classes with '@Entity'?\",\n                    clazzName));\n        }\n        return getSession(persistentUnitName);\n    }\n\n    public SessionType getSession(String persistentUnitName) {\n        ArcContainer arcContainer = Arc.container();\n        if (persistentUnitName == null || PersistenceUnitUtil.isDefaultPersistenceUnit(persistentUnitName)) {\n            return arcContainer.instance(sessionType).get();\n        } else {\n            return arcContainer.instance(sessionType,\n                    new PersistenceUnit.PersistenceUnitLiteral(persistentUnitName))\n                    .get();\n        }\n    }\n\n    public SessionType getSession() {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java#L101-L137","documentation":"getSession resolves the Hibernate session for the persistence unit that owns the given entity class by consulting the entity->PU mapping built at augmentation time. When the entity class is absent from that mapping, Panache concludes the class was never recognized as a JPA entity and throws this IllegalStateException.","triggerScenarios":"Calling any Panache entity/repository operation (count, deleteAll, session(), etc.) with a class name that is not an @Entity — e.g. a DTO, an abstract base class, or a class missing the @Entity annotation.","commonSituations":"Forgetting @Entity on a class extending PanacheEntity; passing a projection DTO to Panache query methods; entity living in a module without Jandex indexing so the build missed it; typo in entity class name when calling getSession directly.","solutions":["Annotate the class with @Entity (and ensure it extends PanacheEntity or has @Id)","Verify the class is a managed JPA entity, not a DTO or base class","Ensure the entity is in a Jandex-indexed module and the app was re-built","If using multiple persistence units, confirm the entity is actually registered in one"],"exampleFix":"// before\npublic class Person extends PanacheEntity { }\n// after\n@Entity\npublic class Person extends PanacheEntity { }","handlingStrategy":"validation","validationCode":"if (!clazz.isAnnotationPresent(jakarta.persistence.Entity.class)) {\n    throw new IllegalArgumentException(clazz + \" is not a JPA @Entity\");\n}","typeGuard":"boolean isJpaEntity(Class<?> c) {\n    return c.isAnnotationPresent(jakarta.persistence.Entity.class);\n}","tryCatchPattern":"try {\n    Person.count();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"was not found\")) {\n        // add @Entity to the class and rebuild\n    } else throw e;\n}","preventionTips":["Annotate every Panache entity with @Entity","Never pass DTOs or projection classes to entity operations","Keep entities in Jandex-indexed modules","Run a clean build after adding new entities"],"tags":["quarkus","panache","jpa","entity"],"backgroundTag":"missing-entity-annotation","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"}