Reputation: 39879
I have a two models, the second is mapping to the same first model twice, with specific values (it has the role of a ManyToMany table with added values) :
public class ModelB extend Model {
public ModelA parent;
public ModelA child;
public String value;
public boolean verified = true;
}
In ModelA :
@OneToMany(mappedBy="child")
List<ModelB> items;
If no entries are in the database for ModelB and I do a modelA.items.size()
=> 1!
Why 1 ? It should be 0.
This results in an error regarding the boolean and some other unexplained.
How can I fix it?
Upvotes: 0
Views: 257
Reputation: 11
I ran into the same issue and was able to solve it by adding an identity column to the secondary table (ModelB). I did not investigate the cause but I suppose Ebean needs a primary key on the table in these kind of situations.
Upvotes: 0
Reputation: 11
http://www.avaje.org/ebean/introquery_joinquery.html
It appears that when joining using a "fetch join" as described in the link above, presumably this is the behavior of Ebean currently. However you can work around that by performing a "Query join" for the OneToMany relation like this:
List<Order> orders =
Ebean.find(Order.class)
.fetch("customer", new FetchConfig().query())
.findList();
Upvotes: 1