hibernate/hibernate-orm · error · IllegalArgumentException
Read-only is not relevant for non-select NativeQuery
Error message
Read-only is not relevant for non-select NativeQuery
What it means
Error "Read-only is not relevant for non-select NativeQuery" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:897
if ( mapping instanceof EntityMapping<?> entityMapping ) {
final var lockMode = LockMode.fromJpaLockMode( entityMapping.lockMode() );
if ( lockMode.greaterThan( LockMode.READ ) ) {
setHibernateLockMode( lockMode );
}
}
}
@Override
@Nullable
public PessimisticLockScope getLockScope() {
//noinspection removal
return queryOptions.getLockOptions().getLockScope();
}
@Override
protected void applyReadOnlyHint(String hintName, Object value) {
if ( isNotSelectForSure() ) {
throw new IllegalArgumentException( "Read-only is not relevant for non-select NativeQuery" );
}
super.applyReadOnlyHint( hintName, value );
}
@Override
protected void applyFetchSizeHint(String hintName, Object value) {
if ( isNotSelectForSure() ) {
throw new IllegalArgumentException( "Fetch-size is not relevant for non-select NativeQuery" );
}
super.applyFetchSizeHint( hintName, value );
}
@Override
protected void applyResultCachingHint(String hintName, Object value) {
if ( isNotSelectForSure() ) {
throw new IllegalArgumentException( "Result-caching is not relevant for non-select NativeQuery" );
}
super.applyResultCachingHint( hintName, value );View on GitHub (pinned to fad1729dce)
Solutions
- setReadOnly only applies to selecting queries; the query is a non-select native query.
- Remove the setReadOnly call for mutation native queries.
When it happens
Trigger: An API operation is invoked on a query object that does not support it.
Common situations: Calling query hint, locking, pagination, conversion, or mutation APIs on a query kind (native vs HQL, select vs mutation) that does not implement them.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/63812bdb87a86e58.
Report an issue: GitHub.