GH-8998: Catch DataIntegrityViolationException instead
Fixes: #8998
Apparently some databases don't throw a proper code to identify a `DuplicateKeyException`, so better to catch `DataIntegrityViolationException` with the same meaning.
(cherry picked from commit 676733ccf7)
This commit is contained in:
committed by
Spring Builds
parent
4864f1c2c4
commit
d3f3a4ab2c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.FindAndModifyOptions;
|
||||
@@ -237,7 +237,7 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
|
||||
try {
|
||||
this.mongoTemplate.insert(document, this.collectionName);
|
||||
}
|
||||
catch (DuplicateKeyException e) {
|
||||
catch (DataIntegrityViolationException e) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("The Message with id [" + document.getMessageId() + "] already exists.\n" +
|
||||
"Ignoring INSERT and SELECT existing...");
|
||||
|
||||
Reference in New Issue
Block a user