【问题标题】:Find where many to many is empty or condition in related not match查找多对多为空或相关条件不匹配的位置
【发布时间】:2012-12-06 09:59:13
【问题描述】:

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

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】:

你需要这样做:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 2018-05-07
    相关资源
    最近更新 更多