hibernate/hibernate-orm · error · UnknownProfileException
No fetch profile named '{}'
Error message
No fetch profile named '{}' What it means
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>.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/loader/internal/IdentifierLoadAccessImpl.java:238
else {
final var enhancementMetadata = entityPersister.getBytecodeEnhancementMetadata();
if ( enhancementMetadata.isEnhancedForLazyLoading()
&& enhancementMetadata.extractLazyInterceptor( result )
instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
lazinessInterceptor.forceInitialize( result, null );
}
}
}
}
private static boolean isLoadByIdComplianceEnabled(SessionFactoryImplementor factory) {
return factory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();
}
@Override
public IdentifierLoadAccess<T> enableFetchProfile(String profileName) {
if ( !context.getSession().getFactory().containsFetchProfileDefinition( profileName ) ) {
throw new UnknownProfileException( profileName );
}
if ( enabledFetchProfiles == null ) {
enabledFetchProfiles = new HashSet<>();
}
enabledFetchProfiles.add( profileName );
if ( disabledFetchProfiles != null ) {
disabledFetchProfiles.remove( profileName );
}
return this;
}
@Override
public IdentifierLoadAccess<T> disableFetchProfile(String profileName) {
if ( disabledFetchProfiles == null ) {
disabledFetchProfiles = new HashSet<>();
}
disabledFetchProfiles.add( profileName );
if ( enabledFetchProfiles != null ) {View on GitHub (pinned to fad1729dce)
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.
Example fix
// before
Order o = session.byId(Order.class).enableFetchProfile("order.ful").load(42L);
// after: @FetchProfile(name = "order-full", ...) declared on Order
Order o = session.byId(Order.class).enableFetchProfile("order-full").load(42L); Defensive patterns
Strategy: validation
Validate before calling
if ( !sessionFactory.containsFetchProfileDefinition( "order-full" ) ) {
throw new IllegalStateException( "Fetch profile not registered: order-full" );
}
Order o = session.byId( Order.class ).enableFetchProfile( "order-full" ).load( 42L ); Try / catch
try {
access = session.byId( Order.class ).enableFetchProfile( profile );
}
catch ( org.hibernate.UnknownProfileException e ) {
log.warn( "Skipping unknown fetch profile {}", profile );
access = session.byId( Order.class );
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Renamed fetch profiles; profiles annotated on classes not scanned; XML mapping files missing from the bootstrap config; partial test metadata.
Related errors
- No fetch profile named '{}'
- Fetch profile object or name is null: %s
- Named query definition is null
- Named query definition name is null: %s
- Duplicate named query '%s'
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e8bb1f68f07967dc.
Report an issue: GitHub.