Morphia中的项目属性和参考元素是否可能?
我的结构类似于:
@Entity
public class Event {
@Embedded
private List<Edition> editions;
}
public class Edition {
@Reference
private List<Lecture> lectures
}
当我尝试投影参考元素的一些属性时,如下所示:
final MorphiaIterator<Event, Event> aggregate = this.basicDAO.getDs().
<Event, Event>createAggregation(Event.class).
match(query).
project(
Projection.projection("editions.address"),
Projection.projection("editions.ageLimit"),
Projection.projection("editions.bannerURL"),
Projection.projection("editions.description"),
Projection.projection("editions.endsIn"),
Projection.projection("editions.establishment"),
Projection.projection("editions.iconURL"),
Projection.projection("editions.id"),
Projection.projection("editions.observation"),
Projection.projection("editions.startsIn"),
Projection.projection("editions.lectures.endsIn"),
Projection.projection("editions.lectures.name"),
Projection.projection("editions.lectures.startsIn"),
Projection.projection("editions.position"),
Projection.projection("name")
).
aggregate(Event.class);
return aggregate.next();
我收到以下消息:
java.lang.RuntimeException: java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef
实际上,这只是一个怀疑基础,事实上我可以执行另一个查询来只检索我想要的属性然后完成我的对象