我正在关注How can I sort related entities in Ebean?,但我收到了此错误
RuntimeException: Can not find Master [class models.Card]
in Child[models.FinalMark]
解决方案忘了放这个吗?即使ID不能正常工作。
@Id
public Integer id;
我认为我的情况非常相似。
@Entity
public class Club extends Model {
@Id
public Long id;
public String name;
@OneToMany(cascade = CascadeType.ALL)
@OrderBy("name asc")
public List<Male> male = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
@OrderBy("name asc")
public List<Female> female = new ArrayList<>();
private static Finder<Long, Club> find =
new Finder<>(Long.class, Club.class);
}
@Entity
public class Male extends Model {
@Id
public Long id;
public String name;
private static Finder<Long, Male> find = new Finder<>(Long.class, Male.class);
}
@Entity
public class Female extends Model {
@Id
public Long id;
@ManyToOne
public Club club;
public String name;
private static Finder<Long, Female> find = new Finder<>(Long.class, Female.class);
}
我有初始数据
male:
- !!models.Male &m1
name: "Martin"
- !!models.Male &m2
name: "Alan"
female:
- !!models.Female &f1
name: "June"
- !!models.Female &f2
name: "Babe"
club:
- !!models.Club
name: "BigClub"
male:
- *m1
- *m2
female:
- *f1
- *f2
在初始化期间。
Map<String, List<Object>> all = (Map<String, List<Object>>) Yaml
.load("initial-data.yml");
// Insert club
Ebean.save(all.get("club"));
当我打电话给Club.find.all()时,男性和女性的领域仍然没有提升。我尝试了两种不同的方式(每种方式都是男性和女性)。两者也没有在asc中排序。任何想法?
答案 0 :(得分:0)
在配置order-by时需要指定相关对象的“路径”,如下所示:
@OneToMany(cascade = CascadeType.ALL)
@OrderBy("male.name asc")
public List<Male> male = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL)
@OrderBy("female.name asc")
public List<Female> female = new ArrayList<>();
否则,它认为您指的是当前类的“name”字段。