I'm using Ninja framework and I'm trying to create a table that has two lists of other tables of the same kind. The problem is that all the content from the other list is also inside of the other list.
Main:
test();
List<Foo> foos = Foo.find.all();
for(Foo foo : foos){
System.out.println("Printing bars1, size: " + foo.getBars1().size());
for(Bar bar : foo.getBars1()){
System.out.println(bar.getText());
}
System.out.println("Printing bars2, size: " + foo.getBars2().size());
for(Bar bar : foo.getBars2()){
System.out.println(bar.getText());
}
}
Function test:
private void test() {
Foo foo = new Foo();
Bar bar1 = new Bar();
Bar bar2 = new Bar();
bar1.setText("This should only be in bars1");
bar2.setText("This should only be in bars2");
foo.getBars1().add(bar1);
foo.getBars2().add(bar2);
foo.save();
}
Foo:
package models;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
@Entity
public class Foo extends BaseModel {
public static final Find<Long, Foo> find = new Find<Long, Foo>() {};
@OneToMany(cascade = CascadeType.ALL)
private List<Bar> bars1;
@OneToMany(cascade = CascadeType.ALL)
private List<Bar> bars2;
public List<Bar> getBars1() {
return bars1;
}
public void setBars1(List<Bar> bars1) {
this.bars1 = bars1;
}
public List<Bar> getBars2() {
return bars2;
}
public void setBars2(List<Bar> bars2) {
this.bars2 = bars2;
}
}
Bar:
package models;
import javax.persistence.Entity;
import javax.validation.constraints.Size;
@Entity
public class Bar extends BaseModel {
public static final Find<Long, Bar> find = new Find<Long, Bar>() {};
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
Print from main:
Printing bars1, size: 2
This should only be in bars1
This should only be in bars2
Printing bars2, size: 2
This should only be in bars1
This should only be in bars2
Expected:
Printing bars1, size: 1
This should only be in bars1
Printing bars2, size: 1
This should only be in bars2
It was a detected issue according: https://github.com/ebean-orm/avaje-ebeanorm/issues/445
is needed to specify a unique join name, I tried this change in your Foo class and it worked:
log
Hope it helps.