hibernate/hibernate-orm · error · HibernateException
Force-increment lock not supported for '@Version' property…
Error message
Force-increment lock not supported for '@Version' property with OnExecutionGenerator
What it means
Mapping/configuration guard during force-increment version locking: the @Version property uses an OnExecutionGenerator (e.g. a database-generated value) which cannot participate in a force-increment lock. The code first tries to fall back to treating the generator as a BeforeExecutionGenerator; this error fires when that fallback is not possible for the configured generator. The faulty input is the entity's version-property generator configuration combined with an OPTIMISTIC_FORCE_INCREMENT lock.
Solutions
- Use a standard @Version column (not an OnExecutionGenerator) if force-increment locking is required, or avoid LockModeType.OPTIMISTIC_FORCE_INCREMENT on this entity.
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown when a force-increment optimistic lock is requested on an entity whose @Version property uses an OnExecutionGenerator.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/30bde500c7d0c28f.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java:2295
}
private BeforeExecutionGenerator generatorForForceIncrement() {
if ( versionPropertyGenerator() instanceof BeforeExecutionGenerator generator
&& generator.generatesOnForceIncrement() ) {
// Special case to accommodate the fact that we don't yet
// allow OnExecutionGenerators with force-increment locking.
// When possible, falls back to treating the generator as a
// BeforeExecutionGenerator. In particular, this works for
// CurrentTimestampGeneration. But it requires an additional
// request to the database to generate the timestamp. This
// solution is neither particularly elegant nor efficient.
return generator;
}
else if ( isVersionGeneratedOnExecution() ) {
// TODO: Ideally, we would allow this case, producing an
// UPDATE statement which sets the version column.
// Then we could remove the previous special case.
throw new HibernateException( "Force-increment lock not supported for '@Version' property with OnExecutionGenerator" );
}
else {
final var generator = getVersionGenerator();
if ( !generator.generatesOnForceIncrement() ) {
throw new HibernateException( "Force-increment lock not supported for '@Version' generator" );
}
return generator;
}
}
/**
* Retrieve the version number
*/
@Override
public Object getCurrentVersion(Object id, SharedSessionContractImplementor session) throws HibernateException {
if ( CORE_LOGGER.isTraceEnabled() ) {
CORE_LOGGER.readingEntityVersion( infoString( this, id, getFactory() ) );View on GitHub (pinned to fad1729dce)