我正在使用Morphia 0.107。
为什么MorphiaIterator类的构建方式只能迭代一次?
import com.mongodb.MongoClient;
import java.net.UnknownHostException;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
import org.mongodb.morphia.query.Query;
public class App {
public static void main(String[] args) throws UnknownHostException {
Morphia m = new Morphia();
Datastore ds = m.createDatastore(new MongoClient(), "test");
Query<Person> q = ds.createQuery(Person.class);
// MorphiaIterator
Iterable<Person> iterable = q.fetchEmptyEntities();
System.out.println(iterable.iterator().hasNext());
for (Person person : iterable) {
System.out.println(person);
}
System.out.println(iterable.iterator().hasNext());
for (Person person : iterable) {
System.out.println(person);
}
// This should work, but throws java.util.NoSuchElementException
ds.delete(Person.class, q.fetchKeys());
}
}