{"record":{"id":"96f9e36a4c3b9237","repo":"hibernate/hibernate-orm","slug":"entity-is-not-a-dynamic-entity","errorCode":null,"errorMessage":"Entity '{}' is not a dynamic entity","messagePattern":"Entity '(.+?)' is not a dynamic entity","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java","lineNumber":68,"sourceCode":"\t\treturn new RootGraphImpl<>( null, (EntityDomainType<T>) rootType );\n\t}\n\n\t/**\n\t * Create a new entity graph rooted at the given\n\t * {@linkplain RepresentationMode#MAP dynamic entity}, without\n\t * needing a reference to the session or session factory.\n\t *\n\t * @param rootType The {@link EntityType} representing the root\n\t *                 entity of the graph, which must be a dynamic\n\t *                 entity\n\t * @return a new mutable {@link EntityGraph}\n\t *\n\t * @since 7.0\n\t */\n\tpublic static EntityGraph<Map<String,?>> createGraphForDynamicEntity(EntityType<?> rootType) {\n\t\tfinal var domainType = (EntityDomainType<?>) rootType;\n\t\tif ( domainType.getRepresentationMode() != RepresentationMode.MAP ) {\n\t\t\tthrow new IllegalArgumentException( \"Entity '\" + domainType.getHibernateEntityName()\n\t\t\t\t\t\t\t\t\t\t\t\t+ \"' is not a dynamic entity\" );\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\") //Safe, because we just checked\n\t\tfinal var dynamicEntity = (EntityDomainType<Map<String, ?>>) domainType;\n\t\treturn new RootGraphImpl<>( null, dynamicEntity );\n\t}\n\n\t/**\n\t * Merges multiple entity graphs into a single graph that specifies the\n\t * fetching/loading of all attributes the input graphs specify.\n\t *\n\t * @param <T> Root entity type of the query and graph.\n\t *\n\t * @param entityManager {@code EntityManager} to use to create the new merged graph.\n\t * @param root Root type of the entity for which the graph is being merged.\n\t * @param graphs Graphs to merge.\n\t *\n\t * @return The merged graph.","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/graph/EntityGraphs.java#L50-L86","documentation":"EntityGraphs.createGraphForDynamicEntity(EntityType) builds a graph for dynamic-map entities — entities mapped without a Java class (RepresentationMode.MAP), whose attributes are held in a Map<String,?>. Passing a regular POJO-mapped EntityType (RepresentationMode.POJO) throws IllegalArgumentException.","triggerScenarios":"Calling createGraphForDynamicEntity with a metamodel EntityType obtained for a normal @Entity class or a POJO hbm mapping; only entity-name/dynamic-map representations qualify.","commonSituations":"Domains that mix dynamic-map entities (legacy hbm entity-name mappings) with annotated POJOs; code copied from dynamic-entity examples; refactoring dynamic entities to POJO classes while keeping the graph helper.","solutions":["For POJO entities use EntityGraphs.createGraph(EntityType) or EntityManager.createEntityGraph(Class)","If the entity is meant to be dynamic, map it with dynamic-map representation (entity-name, no class)","Guard the call: check ((EntityDomainType<?>) type).getRepresentationMode() == RepresentationMode.MAP before invoking"],"exampleFix":"// before\nEntityGraph<Map<String, ?>> graph =\n        EntityGraphs.createGraphForDynamicEntity(metamodel.entity(Order.class)); // POJO → throws\n\n// after\nEntityGraph<Order> graph = EntityGraphs.createGraph(metamodel.entity(Order.class));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isDynamicEntity(EntityType<?> entityType) {\n    return entityType instanceof org.hibernate.metamodel.model.domain.EntityDomainType<?> domainType\n            && domainType.getRepresentationMode() == RepresentationMode.MAP;\n}","tryCatchPattern":null,"preventionTips":["Use createGraphForDynamicEntity only for entity-name (dynamic-map) mappings","Route graph creation through one helper that checks representation mode and falls back to EntityGraphs.createGraph","Keep dynamic-map entities isolated from the annotated POJO model"],"tags":["hibernate","entity-graph","dynamic-entity","metamodel"],"backgroundTag":"entity-graph-misuse","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}