Skip to content

Adapt DuplicateKeyException on insertSessionAttributes to new SQL Exception Translator #2108

Closed
@marcusdacoregio

Description

@marcusdacoregio

The commit spring-projects/spring-framework@083113d changed the way that exceptions are translated from the database exception. In some of our tests, what before was a DuplicateKeyException now is a DataIntegrityViolationException and we ignore the DataIntegrityViolationException. See:

try {
this.jdbcOperations.update(this.createSessionAttributeQuery, (ps) -> {
String attributeName = attributeNames.get(0);
ps.setString(1, session.primaryKey);
ps.setString(2, attributeName);
lobCreator.setBlobAsBytes(ps, 3, serialize(session.getAttribute(attributeName)));
});
}
catch (DuplicateKeyException ex) {
throw ex;
}
catch (DataIntegrityViolationException ex) {
// parent record not found - we are ignoring this error because we
// assume that a concurrent request has removed the session
}

The code should be adapted to the new behavior. It is important to note that in case of a duplicate key we should still consider throwing an exception since it is a clue to users that they need to expose a SessionRepositoryCustomizer Bean (see #1213)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions