我升级了我的应用程序以使用 Objectify4,但我无法让订购工作。这是我所做的:我有一个要查询的课程。这个类是从 Mail 和 Model 扩展而来的。order 的属性应该是在 Mail-Class 中索引的日期时间。
import com.googlecode.objectify.annotation.EntitySubclass;
import com.googlecode.objectify.annotation.Serialize;
@EntitySubclass(index=true)
public class Offer extends Mail {
private static final long serialVersionUID = -6210617753276086669L;
@Serialize private Article debit;
@Serialize private Article credit;
private boolean accepted;
...
}
import com.googlecode.objectify.annotation.EntitySubclass;
import com.googlecode.objectify.annotation.Index;
@EntitySubclass(index=true)
public class Mail extends Model {
private static final long serialVersionUID = 8417328804276215057L;
@Index private Long datetime;
@Index private String sender;
@Index private String receiver;
...}
import java.io.Serializable;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Ignore;
import com.googlecode.objectify.annotation.Index;
@Entity
public class Model implements Serializable {
private static final long serialVersionUID = -5821221296324663253L;
@Id Long id;
@Index String name;
@Ignore transient private Model parent;
@Ignore transient private boolean changed;
...}
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
public class DatabaseService {
static {
ObjectifyService.register(Model.class);
ObjectifyService.register(Mail.class);
ObjectifyService.register(Offer.class);
}
public static Objectify get() {
return ObjectifyService.ofy();
}
}
这就是我想要做的:
Query<Offer> result = DatabaseService.get().load().type(Offer.class).order("-datetime");
不幸的是,结果总是没有排序。
有没有人暗示?