【问题标题】:Ebean: weird resultsEbean:奇怪的结果
【发布时间】:2023-03-18 06:53:01
【问题描述】:

这是我的主题的数据成员:

public class Topic extends Model {  
@Id  
protected long id;  
public String title;  
public String content;  
@ManyToOne  
@JoinColumn(name = "forumId")  
public Forum forum;  // this is a reference to the topic's forum. 

在 postgresql 中保存为 bigint(论坛类的 id)的论坛属性

这是我的主题查找器:

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

现在,我正在尝试使用 Finder 做最简单的事情。按论坛 ID 检索主题。
我尝试了很多变体,这是其中之一:

public static List<Topic> getTopicsByForum(long id) {
    Forum forum = Forum.getById(id);
    return find.where().gt("forumId", forum).findList();
}

我得到错误的结果。我必须做错事,但不知道是什么。

【问题讨论】:

    标签: java database playframework-2.0 ebean


    【解决方案1】:

    使用 Ebean,您可以直接访问属性,所以试试这个:

    public static List<Topic> getTopicsByForum(Long forumId) {
        return find.where().eq("forum.id", forumId).findList();
    }
    

    【讨论】:

    • 好的,它有效。但我需要将属性名称从“forumId.id”更改为“forum.id”。
    • 啊,是的,对不起;它必须是属性名(而不是列名)。
    猜你喜欢
    • 1970-01-01
    • 2016-11-28
    • 2012-12-16
    • 2012-12-06
    • 2016-08-24
    • 2018-01-24
    • 2021-03-01
    • 2014-08-17
    • 1970-01-01
    相关资源
    最近更新 更多