DATAKV-89 - KeyValueTemplate now throws DuplicateKeyException.
We now throw DuplicateKeyException instead of InvalidDataAccessApiUsageException in case an object with given id already exists. Original pull request: spring-projects/spring-data-commons#106.
This commit is contained in:
committed by
Oliver Gierke
parent
42a13a7403
commit
5f62882a3e
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -117,7 +118,8 @@ public class KeyValueTemplate implements KeyValueOperations {
|
||||
String typeKey = resolveKeySpace(objectToInsert.getClass());
|
||||
|
||||
if (adapter.contains(id, typeKey)) {
|
||||
throw new InvalidDataAccessApiUsageException("Cannot insert existing object. Please use update.");
|
||||
throw new DuplicateKeyException(String.format(
|
||||
"Cannot insert existing object with id %s!. Please use update.", id));
|
||||
}
|
||||
|
||||
adapter.put(id, objectToInsert, typeKey);
|
||||
|
||||
Reference in New Issue
Block a user