0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Cyril N.
  • 38,875
  • 36
  • 142
  • 243
  • take from the list first element and tell us what is it. Is it null ? Or is this an object with values ? – Fixus Apr 26 '12 at 05:57
  • It's an object of ModelB, but with all the field at null. I double checked the database, and the table is empty! – Cyril N. Apr 26 '12 at 07:02
  • try setting default value in ModelA: List items = new List(); – Fixus Apr 26 '12 at 07:31

2 Answers2

1

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(); 
Morghus
  • 11
  • 1
0

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.