Fix for problem loading domain classes with DBRef on them.
This commit is contained in:
@@ -553,10 +553,10 @@ public class MappingMongoConverter implements MongoConverter, ApplicationContext
|
||||
o = x.getValue(ctx);
|
||||
} else {
|
||||
DBObject from = dbo;
|
||||
if (dbo instanceof DBRef) {
|
||||
from = ((DBRef) dbo).fetch();
|
||||
Object dbObj = dbo.get(name);
|
||||
if (dbObj instanceof DBRef) {
|
||||
dbObj = ((DBRef) dbObj).fetch();
|
||||
}
|
||||
Object dbObj = from.get(name);
|
||||
if (dbObj instanceof DBObject) {
|
||||
if (prop.isMap() && dbObj instanceof DBObject) {
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ public class MappingTests {
|
||||
"personcustomidname",
|
||||
"personmultidimarrays",
|
||||
"personmulticollection",
|
||||
"personwithdbref",
|
||||
"person1",
|
||||
"person2",
|
||||
"account"
|
||||
@@ -299,4 +300,16 @@ public class MappingTests {
|
||||
assertThat(result.get(0).getGrid().size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbRef() {
|
||||
GeoLocation geo = new GeoLocation(new double[]{37.0625, -95.677068});
|
||||
template.insert(geo);
|
||||
|
||||
PersonWithDbRef p = new PersonWithDbRef(4321, "With", "DBRef", geo);
|
||||
template.insert(p);
|
||||
|
||||
List<PersonWithDbRef> result = template.find(new Query(Criteria.where("ssn").is(4321)), PersonWithDbRef.class);
|
||||
assertThat(result.size(), is(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.document.mongodb.mapping;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class PersonWithDbRef extends BasePerson {
|
||||
|
||||
@DBRef
|
||||
private GeoLocation home;
|
||||
|
||||
public PersonWithDbRef(Integer ssn, String firstName, String lastName, GeoLocation home) {
|
||||
super(ssn, firstName, lastName);
|
||||
this.home = home;
|
||||
}
|
||||
|
||||
public GeoLocation getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
public void setHome(GeoLocation home) {
|
||||
this.home = home;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user