Skip to content

Commit aa94580

Browse files
committed
Fix BaseMorphiaRepository.get(id) returning wrong document
1 parent 86aaddf commit aa94580

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 3.1.1 (2020-02-05)
2+
3+
* [fix] Fix `BaseMorphiaRepository.get(id)` always returning the first document from the collection (ignoring given id).
4+
15
# Version 3.1.0 (2020-01-31)
26

37
* [new] Morphia repository now has the ability to stream results from the database as consumed (using a cursor instead of a list behind the scenes).

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.seedstack.addons.mongodb</groupId>
1616
<artifactId>mongodb</artifactId>
17-
<version>3.1.0-SNAPSHOT</version>
17+
<version>3.1.1-SNAPSHOT</version>
1818
</parent>
1919

2020
<artifactId>mongodb-core</artifactId>

morphia/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.seedstack.addons.mongodb</groupId>
1616
<artifactId>mongodb</artifactId>
17-
<version>3.1.0-SNAPSHOT</version>
17+
<version>3.1.1-SNAPSHOT</version>
1818
</parent>
1919

2020
<artifactId>mongodb-morphia</artifactId>

morphia/src/main/java/org/seedstack/mongodb/morphia/BaseMorphiaRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Stream<A> get(Specification<A> specification, Option... options) {
9090

9191
@Override
9292
public Optional<A> get(ID id) {
93-
return Optional.ofNullable(datastore.createQuery(getAggregateRootClass()).first());
93+
return Optional.ofNullable(datastore.find(getAggregateRootClass()).filter(ID_KEY, id).first());
9494
}
9595

9696
@Override

morphia/src/test/java/org/seedstack/mongodb/morphia/MorphiaRepositoryIT.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ public void setUp() throws Exception {
3434

3535
@Test
3636
public void addAndGet() throws Exception {
37-
User user1 = createUser(1L, "someFirstName", "someLastName");
37+
User user1 = createUser(1L, "someFirstName1", "someLastName1");
38+
User user2 = createUser(2L, "someFirstName2", "someLastName2");
3839
userRepository.add(user1);
39-
Optional<User> loaded = userRepository.get(1L);
40+
userRepository.add(user2);
41+
Optional<User> loaded = userRepository.get(2L);
4042
assertThat(loaded).isPresent();
41-
assertThat(loaded.get().getName()).isEqualTo("someFirstName");
42-
assertThat(loaded.get().getLastname()).isEqualTo("someLastName");
43+
assertThat(loaded.get().getName()).isEqualTo("someFirstName2");
44+
assertThat(loaded.get().getLastname()).isEqualTo("someLastName2");
45+
assertThat(userRepository.get(3L)).isNotPresent();
4346
}
4447

4548
@Test

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<groupId>org.seedstack.addons.mongodb</groupId>
2121
<artifactId>mongodb</artifactId>
22-
<version>3.1.0-SNAPSHOT</version>
22+
<version>3.1.1-SNAPSHOT</version>
2323
<packaging>pom</packaging>
2424

2525
<properties>

0 commit comments

Comments
 (0)