hibernate/hibernate-orm · error · IllegalStateException
LockModeType not supported for native query
Error message
LockModeType not supported for native query
What it means
Error "LockModeType not supported for native query" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:753
@Override
@Nullable
public Class<R> getTargetType() {
return resultType;
}
@Override
@Nonnull
public NativeQueryImplementor<R> setTimeout(@Nullable Timeout timeout) {
super.setTimeout( timeout );
return this;
}
@Override
@Nullable
public LockModeType getLockMode() {
// JPA says this is illegal
throw new IllegalStateException( "LockModeType not supported for native query" );
}
@Override
@Nonnull
public NativeQueryImplementor<R> setLockMode(@Nonnull LockModeType lockModeType) {
// JPA says this is illegal
throw new IllegalStateException( "LockModeType not supported for native query" );
}
@Override
@Nonnull
public NativeQueryImplementor<R> setHibernateLockMode(@Nonnull LockMode lockMode) {
//noinspection removal
queryOptions.getLockOptions().setLockMode( lockMode );
return this;
}
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- LockModeType cannot be applied to native queries.
- Remove the lock mode hint, or use HQL/criteria queries, or express locking in SQL (e.g. FOR UPDATE).
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/b98181eab3edb181.
Report an issue: GitHub.