hibernate/hibernate-orm · error · PersistenceException
Hibernate cannot unwrap '" + getClass().getName() + "' as '"
Error message
Hibernate cannot unwrap '" + getClass().getName() + "' as '" + type.getName() + "'
What it means
Error "Hibernate cannot unwrap '" + getClass().getName() + "' as '" + type.getName() + "'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1889
return CacheLoadHelper.loadFromSecondLevelCache( this, instanceToLoad, lockMode, persister, entityKey );
}
@Override
@Nonnull
public TransactionCompletionCallbacksImplementor getTransactionCompletionCallbacksImplementor() {
return transactionCompletionCallbacks.forSharing();
}
@Override
@Nonnull
public <T> T unwrap(@Nonnull Class<T> type) {
checkOpen();
if ( type.isInstance( this ) ) {
return type.cast( this );
}
throw new PersistenceException( "Hibernate cannot unwrap '" + getClass().getName()
+ "' as '" + type.getName() + "'" );
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Unwrap only to interfaces supported by StatelessSession (e.g. StatelessSession itself, SharedSessionContractImplementor); otherwise adapt manually.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1889 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/1a6510f8c859e73a.
Report an issue: GitHub.