2012-03-23 51 views
1

我兩個班這種方式設置:Ebean在播放2.0 - 沒有加入對生成的查詢

public class Listing extends Model { 
    @ManyToOne 
    @JoinColumn(name = "user_id", nullable = false) 
    public User user; 

    public String name; 
} 


public class User extends Model {  
    @Id 
    @Constraints.Required 
    @Formats.NonEmpty 
    public String username; 

    @OneToMany(mappedBy="user") 
    public List<Listing> listing; 
} 

的問題是,查詢只返回特定用戶的人數確實有它加入成爲我會期待它,但有像這樣的:

select t0.name 
from listing t0 
where t0.user_id = '[email protected]' 

任何想法我做錯了什麼?

回答

2

您需要定義連接的明確性以便從Listing表中獲取元素。

在用戶等級:

find.fetch("listing").findList(); 
+0

感謝朱利安!我在錯誤的字段中定義'@Id'的地方也犯了一個錯誤。應在公共Long ID上定義'@Id';而不是用戶名。 – 2012-03-25 02:08:51