{"record":{"id":"a1c5cec38cb0927e","repo":"hibernate/hibernate-orm","slug":"no-fetch-profile-named-a1c5ce","errorCode":null,"errorMessage":"No fetch profile named '{}'","messagePattern":"No fetch profile named '(.+?)'","errorType":"exception","errorClass":"UnknownProfileException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/loader/internal/BaseNaturalIdLoadAccessImpl.java","lineNumber":99,"sourceCode":"\n\n\tprotected Object with(Timeout timeout) {\n\t\tif ( lockOptions == null ) {\n\t\t\tlockOptions = new LockOptions();\n\t\t}\n\t\tlockOptions.setTimeOut( timeout.milliseconds() );\n\t\treturn this;\n\t}\n\n\tpublic Object with(EntityGraph<T> graph, GraphSemantic semantic) {\n\t\tthis.rootGraph = (RootGraphImplementor<T>) graph;\n\t\tthis.graphSemantic = semantic;\n\t\treturn this;\n\t}\n\n\tpublic Object enableFetchProfile(String profileName) {\n\t\tif ( !context.getSession().getFactory().containsFetchProfileDefinition( profileName ) ) {\n\t\t\tthrow new UnknownProfileException( profileName );\n\t\t}\n\t\tif ( enabledFetchProfiles == null ) {\n\t\t\tenabledFetchProfiles = new HashSet<>();\n\t\t}\n\t\tenabledFetchProfiles.add( profileName );\n\t\tif ( disabledFetchProfiles != null ) {\n\t\t\tdisabledFetchProfiles.remove( profileName );\n\t\t}\n\t\treturn this;\n\t}\n\n\tpublic Object disableFetchProfile(String profileName) {\n\t\tif ( disabledFetchProfiles == null ) {\n\t\t\tdisabledFetchProfiles = new HashSet<>();\n\t\t}\n\t\tdisabledFetchProfiles.add( profileName );\n\t\tif ( enabledFetchProfiles != null ) {\n\t\t\tenabledFetchProfiles.remove( profileName );","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/loader/internal/BaseNaturalIdLoadAccessImpl.java#L81-L117","documentation":"Thrown when a natural-id load accessor (session.byNaturalId(...) / bySimpleNaturalId(...)) calls enableFetchProfile(name) with a name the SessionFactory does not know. Fetch profiles are registered only at bootstrap time from @FetchProfile annotations or hbm.xml <fetch-profile> elements; unknown names are rejected immediately instead of being silently ignored.","triggerScenarios":"Calling enableFetchProfile(\"profile\") on a natural-id load access object when no @FetchProfile(name = \"profile\") exists on any mapped entity and no <fetch-profile name=\"profile\"> exists in hbm.xml; a typo between mapping and query code; the profile annotated on a class that is not part of the persistence unit.","commonSituations":"Renaming a fetch profile in mappings but not in service code; @FetchProfile placed on a non-entity helper class or an entity excluded from scanning; hbm.xml files omitted from the mappings list; test SessionFactories built from a reduced entity set.","solutions":["Check the spelling against the mapping and verify registration before enabling: sessionFactory.containsFetchProfileDefinition(name).","Register the profile: @FetchProfile(name = \"...\", entityOverrides = @FetchProfile.EntityOverride(entity = MyEntity.class, associationOverrides = @FetchProfile.AssociationOverride(name = \"assoc\", fetch = FetchMode.JOIN))) on a mapped entity, or <fetch-profile> in hbm.xml.","Make sure the annotated entity is actually in the persistence unit (persistence.xml, scanned package, or hibernate mapping list)."],"exampleFix":"// before: no profile registered, name misspelled\nsession.bySimpleNaturalId(User.class).enableFetchProfile(\"user-orders\").load(\"john\");\n\n// after: profile exists on a mapped entity\n// @FetchProfile(name = \"user-with-orders\",\n//   entityOverrides = @FetchProfile.EntityOverride(entity = User.class,\n//     associationOverrides = @FetchProfile.AssociationOverride(name = \"orders\", fetch = FetchMode.JOIN)))\n// public class User { ... }\nsession.bySimpleNaturalId(User.class).enableFetchProfile(\"user-with-orders\").load(\"john\");","handlingStrategy":"validation","validationCode":"String profile = \"user-with-orders\";\nif ( !sessionFactory.containsFetchProfileDefinition( profile ) ) {\n    throw new IllegalStateException( \"Fetch profile not registered: \" + profile );\n}\nvar access = session.bySimpleNaturalId( User.class ).enableFetchProfile( profile );","typeGuard":null,"tryCatchPattern":"try {\n    access.enableFetchProfile( profile );\n}\ncatch ( org.hibernate.UnknownProfileException e ) {\n    // degrade gracefully: continue with default fetching\n    log.warn( \"Unknown fetch profile {}, falling back to default fetching\", profile );\n}","preventionTips":["Share fetch-profile names as constants between mapping and query code","At startup assert containsFetchProfileDefinition for every profile the application enables","Place @FetchProfile annotations on entities inside the scanned persistence unit"],"tags":["hibernate","fetch-profile","natural-id","orm"],"backgroundTag":"unknown-fetch-profile","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}