查找many to many为空或相关条件不匹配的地方。

问题描述 投票:1回答:1

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

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

所以我卡在这里了。我怎样才能实现这个目标呢?

java playframework-2.0 ebean
1个回答
0
投票

你需要这样做。

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

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

这将创建一个左外连接查询, find.where().IsNull("section")无法使用。

© www.soinside.com 2019 - 2024. All rights reserved.