From 2eaf55fce3f9bd4efe567ec16038db4012f1e4f5 Mon Sep 17 00:00:00 2001 From: eric-martin Date: Fri, 29 Mar 2019 19:57:18 -0500 Subject: [PATCH] BAEL-1961: Fixed UserModelListener.onBeforeConvert() --- .../java/com/baeldung/mongodb/events/UserModelListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java index 24b53f3d2d..2fe81f7ef4 100644 --- a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java @@ -21,7 +21,9 @@ public class UserModelListener extends AbstractMongoEventListener { @Override public void onBeforeConvert(BeforeConvertEvent event) { - event.getSource().setId(sequenceGenerator.generateSequence(User.SEQUENCE_NAME)); + if (event.getSource().getId() < 1) { + event.getSource().setId(sequenceGenerator.generateSequence(User.SEQUENCE_NAME)); + } }