Skip to content

Commit

Permalink
convert key values properly with annotated with idOnly = true
Browse files Browse the repository at this point in the history
fixes #794
(cherry picked from commit d67d0ae)
  • Loading branch information
Justin Lee committed Jun 11, 2015
1 parent 833fd62 commit 1e9b185
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ public Object toMongoObject(final MappedField mf, final MappedClass mc, final Ob
if (key == null) {
mappedValue = toMongoObject(value, false);
} else {
mappedValue = keyToRef(key);
final Reference refAnn = mf.getAnnotation(Reference.class);
mappedValue = refAnn != null && refAnn.idOnly()
? keyToManualRef(key)
: keyToRef(key);
if (mappedValue == value) {
throw new ValidationException("cannot map to @Reference/Key<T>/DBRef field: " + value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ public void testNullReferences() {
getDs().save(container);
allNull(container);
}

@Test
public void testFindByEntityReference() {
final Ref ref = new Ref("refId");
getDs().save(ref);

final Container container = new Container();
container.singleRef = ref;
getDs().save(container);

Assert.assertNotNull(getDs().find(Container.class, "singleRef", ref).get());
}

private void allNull(final Container container) {
Assert.assertNull(container.lazyMapRef);
Expand Down

0 comments on commit 1e9b185

Please sign in to comment.