找到许多对空的地方或相关的条件不匹配

时间:2012-12-06 09:59:14

标签: java playframework-2.0 ebean

这是我的数据库(简化):

User
    @ManyToMany
    List<Section> sections;

    public static Model.Finder<Long,User> find = new Model.Finder<Long, User>(Long.class, User.class);

Section
    Integer year;
    @ManyToMany
    List<User> users;

    public static Model.Finder<Long,Section> find = new Model.Finder<Long, Section>(Long.class, Section.class);

使用Ebean,我需要列出今年(2012年)没有任何相关部分的所有用户(因此,也包括那些根本没有相关部分的用户)。

但是我看不出我会怎么做:/

我试过了:

User.find.where().isNull("sections").findList(); // but it didn't worked

所以我被困在这里。我该怎么办?

感谢您的帮助! :)

1 个答案:

答案 0 :(得分:0)

你需要这样做:

String q="find * fetch sections where sections.id is null"

Ebean.createQuery(User.class,q).findList();

这将创建一个左外连接查询,find.where()。IsNull(“sections”)不起作用。