DATAMONGO-1204 - ObjectPath now uses raw id values to track resolved objects.
We now use the native id within ObjectPath for checking if a DBref has already been resolved. This is required as MongoDB Java driver 3 generation changed ObjectId.equals(…) which now performs a type check. Original pull request: #334. Related pull request: #288.
This commit is contained in:
committed by
Oliver Gierke
parent
c876155d34
commit
b8cb2f74cf
@@ -264,7 +264,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
accessor.setProperty(idProperty, idValue);
|
accessor.setProperty(idProperty, idValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ObjectPath currentPath = path.push(result, entity, idValue);
|
final ObjectPath currentPath = path.push(result, entity, idValue != null ? dbo.get(idProperty.getFieldName())
|
||||||
|
: null);
|
||||||
|
|
||||||
// Set properties not already set in the constructor
|
// Set properties not already set in the constructor
|
||||||
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
|
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
|
||||||
|
|||||||
@@ -3035,7 +3035,7 @@ public class MongoTemplateTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void takesLimitIntoAccountWhenStreaming() {
|
public void takesLimitIntoAccountWhenStreaming() {
|
||||||
|
|
||||||
Person youngestPerson = new Person("John", 20);
|
Person youngestPerson = new Person("John", 20);
|
||||||
Person oldestPerson = new Person("Jane", 42);
|
Person oldestPerson = new Person("Jane", 42);
|
||||||
|
|
||||||
@@ -3049,6 +3049,31 @@ public class MongoTemplateTests {
|
|||||||
assertThat(stream.hasNext(), is(false));
|
assertThat(stream.hasNext(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAMONGO-1204
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void resolvesCyclicDBRefCorrectly() {
|
||||||
|
|
||||||
|
SomeMessage message = new SomeMessage();
|
||||||
|
SomeContent content = new SomeContent();
|
||||||
|
|
||||||
|
template.save(message);
|
||||||
|
template.save(content);
|
||||||
|
|
||||||
|
message.dbrefContent = content;
|
||||||
|
content.dbrefMessage = message;
|
||||||
|
|
||||||
|
template.save(message);
|
||||||
|
template.save(content);
|
||||||
|
|
||||||
|
SomeMessage messageLoaded = template.findOne(query(where("id").is(message.id)), SomeMessage.class);
|
||||||
|
SomeContent contentLoaded = template.findOne(query(where("id").is(content.id)), SomeContent.class);
|
||||||
|
|
||||||
|
assertThat(messageLoaded.dbrefContent.id, is(contentLoaded.id));
|
||||||
|
assertThat(contentLoaded.dbrefMessage.id, is(messageLoaded.id));
|
||||||
|
}
|
||||||
|
|
||||||
static class DoucmentWithNamedIdField {
|
static class DoucmentWithNamedIdField {
|
||||||
|
|
||||||
@Id String someIdKey;
|
@Id String someIdKey;
|
||||||
@@ -3351,6 +3376,7 @@ public class MongoTemplateTests {
|
|||||||
String id;
|
String id;
|
||||||
String text;
|
String text;
|
||||||
String name;
|
String name;
|
||||||
|
@org.springframework.data.mongodb.core.mapping.DBRef SomeMessage dbrefMessage;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
Reference in New Issue
Block a user