【问题标题】:Can't fetch certain types of nested objects in Ebean无法在 Ebean 中获取某些类型的嵌套对象
【发布时间】:2013-01-15 18:48:01
【问题描述】:

我正在尝试获取 Ebean 中的嵌套对象,但它不起作用。我得到User。它有AddressesAddresses 每个都有一个House。但是House 只有一个id。所有其他属性为空。我在this other forum 上读到,Ebean 中可能存在一个错误,但它是从 2011 年开始的。有没有办法让它工作?

注意:地址和房屋具有OneToOne 关系。

注意:为简单起见,我省略了@Entity 和@Id。

public class User {
    @OneToMany
    public List<Address> addresses;

    public static Finder<String, User> find = new Finder(String.class, User.class);

    // This is my query
    public static Event find(Long id) {
        return find.fetch("addresses").fetch("addresses.house").where().eq("id", id).findUnique();
    }
}

public class Address {
    @OneToOne(cascade =  CascadeType.ALL, mappedBy = "address")
    public House house;
}

public class House {
    @OneToOne
    public Address address;
    public String somePropertyThatIsNullWhenIUseMyQuery;
}

【问题讨论】:

标签: orm playframework nested playframework-2.0 ebean


【解决方案1】:
 Ebean.find(User.class).fetch("addresses.house", new FetchConfig().query()) 

为我工作。如果你仍然没有看到它,你可能想要使用

 Address.getHouse().getSomeProperty()

有时你只是将对象传递给 JSON f.e.属性显示为 null :(

【讨论】:

    猜你喜欢
    • 2016-11-12
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多