1

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

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();
}

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

4

1 回答 1

1

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

public static List<Topic> getTopicsByForum(Long forumId) {
    return find.where().eq("forum.id", forumId).findList();
}
于 2012-08-17T13:30:23.687 回答