TomahawkPhant
TomahawkPhant

Reputation: 1160

Can't fetch certain types of nested objects in Ebean

I'm trying to fetch nested objects in Ebean, but it isn't working. I get the User. It has Addresses. The Addresses each have a House. But the House only has an id. All other properties are null. I read on this other forum that there may be a bug in Ebean, but it was from 2011. Is there a way to make this work?

Note: Address and House have a OneToOne relationship.

Note: I left out @Entity and @Id for simplicity.

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

Upvotes: 3

Views: 1900

Answers (1)

Nikki
Nikki

Reputation: 434

 Ebean.find(User.class).fetch("addresses.house", new FetchConfig().query()) 

works for me. If you still dont see it, u might want to use

 Address.getHouse().getSomeProperty()

Sometimes when u just pass the object to JSON f.e. properties shown as null :(

Upvotes: 1

Related Questions