{"record":{"id":"e8bb1f68f07967dc","repo":"hibernate/hibernate-orm","slug":"no-fetch-profile-named-e8bb1f","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/IdentifierLoadAccessImpl.java","lineNumber":238,"sourceCode":"\t\t\telse {\n\t\t\t\tfinal var enhancementMetadata = entityPersister.getBytecodeEnhancementMetadata();\n\t\t\t\tif ( enhancementMetadata.isEnhancedForLazyLoading()\n\t\t\t\t\t\t&& enhancementMetadata.extractLazyInterceptor( result )\n\t\t\t\t\t\t\t\tinstanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {\n\t\t\t\t\tlazinessInterceptor.forceInitialize( result, null );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static boolean isLoadByIdComplianceEnabled(SessionFactoryImplementor factory) {\n\t\treturn factory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();\n\t}\n\n\t@Override\n\tpublic IdentifierLoadAccess<T> 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\t@Override\n\tpublic IdentifierLoadAccess<T> 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 ) {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/loader/internal/IdentifierLoadAccessImpl.java#L220-L256","documentation":"IdentifierLoadAccessImpl.enableFetchProfile validates the profile name against the SessionFactory's registered fetch-profile definitions; session.byId(...).enableFetchProfile(name) with an unregistered name throws UnknownProfileException before any query runs. Profiles are registered only at bootstrap via @FetchProfile or hbm.xml <fetch-profile>.","triggerScenarios":"session.byId(Order.class).enableFetchProfile(\"order-full\") when no such profile is defined; casing or spelling mismatch between mapping and call site; profile defined in an hbm.xml not included in the configuration; profile on an entity outside the persistence unit.","commonSituations":"Renamed fetch profiles; profiles annotated on classes not scanned; XML mapping files missing from the bootstrap config; partial test metadata.","solutions":["Verify with sessionFactory.containsFetchProfileDefinition(name) before enabling.","Define the profile with @FetchProfile on a mapped entity or <fetch-profile> in hbm.xml.","Ensure the defining mapping is part of the bootstrap metadata."],"exampleFix":"// before\nOrder o = session.byId(Order.class).enableFetchProfile(\"order.ful\").load(42L);\n\n// after: @FetchProfile(name = \"order-full\", ...) declared on Order\nOrder o = session.byId(Order.class).enableFetchProfile(\"order-full\").load(42L);","handlingStrategy":"validation","validationCode":"if ( !sessionFactory.containsFetchProfileDefinition( \"order-full\" ) ) {\n    throw new IllegalStateException( \"Fetch profile not registered: order-full\" );\n}\nOrder o = session.byId( Order.class ).enableFetchProfile( \"order-full\" ).load( 42L );","typeGuard":null,"tryCatchPattern":"try {\n    access = session.byId( Order.class ).enableFetchProfile( profile );\n}\ncatch ( org.hibernate.UnknownProfileException e ) {\n    log.warn( \"Skipping unknown fetch profile {}\", profile );\n    access = session.byId( Order.class );\n}","preventionTips":["Define profile names as constants used by both mappings and queries","Startup check: iterate all enabled profiles and assert registration","Keep profile definitions next to the entities they override"],"tags":["hibernate","fetch-profile","by-id","orm"],"backgroundTag":"unknown-fetch-profile","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}