Skip to content

OptimisticLockingUtils fails with IllegalStateException when constructing OptimisticLockingFailureException using flat composite primary keys #1635

@pgehl

Description

@pgehl

We upgraded one of our reactive project using spring-data-cassandra to spring-boot 3.5.9.
This project:

  • defines flat composite primary key using @PrimaryKeyColumn annotation.
  • code did not change

Since the update, the integration test checking that OptimisticLockingFailureException are thrown for duplicate entry fail with (sensitive information replced by generic example information):

java.lang.IllegalStateException: Required identifier property not found for class com.example.cassandra.SampleCassandraData
	at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:135)
	at org.springframework.data.cassandra.core.EntityOperations$MappedEntity.getIdentifier(EntityOperations.java:270)
	at org.springframework.data.cassandra.core.OptimisticLockingUtils.updateFailed(OptimisticLockingUtils.java:54)
	at org.springframework.data.cassandra.core.ReactiveCassandraTemplate.lambda$doUpdateVersioned$16(ReactiveCassandraTemplate.java:638

The issue seems to be when OptimisticLockingUtils

public static OptimisticLockingFailureException updateFailed(EntityOperations.AdaptibleEntity<?> entity) {
	return new OptimisticLockingFailureException(String.format(
		"Failed to update versioned entity with id '%s' (version '%s') in table [%s]; Was the entity updated or deleted concurrently?",
		entity.getIdentifier(), entity.getVersion(), entity.getPersistentEntity().getTableName()));
	}

entity.getIdentifier() calls PersistentEntity.getRequiredIdProperty(). Our entity uses flat composite primary keys and does not have an idProperty.

Libraries and versions:

  • spring-boot-starter-data-cassandra: 3.5.9
  • spring-data-cassandra: 4.5.7

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions