Merge remote-tracking branch 'ebean/master' into pr/bugfix/reuse_update_collection_parameters

This commit is contained in:
Jonas Pöhler committed 2021-10-06 11:57:50 +02:00
commit a592717c77
21 files changed
+119 -71

No files matched your search

@@ -0,0 +1,29 @@
package org.tests.o2m;
import io.ebean.BaseTestCase;
import io.ebean.common.BeanList;
import org.junit.jupiter.api.Test;
import org.tests.model.json.EBasicJsonMap;
import org.tests.o2m.lazy.OmlBaz;
import org.tests.o2m.lazy.OmlFoo;
import static org.assertj.core.api.Assertions.assertThat;
class TestOneToManyEnhancement extends BaseTestCase {
@Test
void test_when_constructorAddsEntry() {
OmlFoo foo = new OmlFoo(new OmlBaz());
assertThat(foo.getBazList()).isInstanceOf(BeanList.class);
assertThat(foo.getBazList()).isNotEmpty();
}
@Test
void test_commonCase() {
EBasicJsonMap bean = new EBasicJsonMap();
assertThat(bean.getDetails()).isInstanceOf(BeanList.class);
assertThat(bean.getDetails()).isEmpty();
}
}
@@ -15,7 +15,12 @@ public class OmlFoo {
private OmlBar bar;
@OneToMany(mappedBy = "foo", cascade = CascadeType.ALL)
private List<OmlBaz> bazList = new ArrayList<OmlBaz>();
private List<OmlBaz> bazList = new ArrayList<>();
public OmlFoo(OmlBaz baz) {
bazList.add(baz);
baz.setFoo(this);
}
public Long getId() {
return id;
@@ -13,11 +13,9 @@ public class TestLazyManyViaPath extends BaseTestCase {
@Test
public void test() {
OmlBar bar = new OmlBar();
List<OmlFoo> fooList = new ArrayList<>();
fooList.add(createNewFooWithBar(bar));
bar.setFooList(fooList);
DB.save(bar);
@@ -30,26 +28,24 @@ public class TestLazyManyViaPath extends BaseTestCase {
// This works
List<OmlFoo> foosList = fooFromDb.getBar().getFooList();
assertThat(fooList.size()).isEqualTo(1);
assertThat(foosList).hasSize(1);
assertThat(fooList).hasSize(1);
OmlBaz bazFromDb = DB
.find(OmlBaz.class)
.where()
.eq("id", bar.getFooList().get(0).getBazList().get(0).getId())
.findOne();
assert bazFromDb != null;
// This does not work and gives the exception
List<OmlFoo> foosList1 = bazFromDb.getFoo().getBar().getFooList();
assertThat(foosList1.size()).isEqualTo(1);
}
private static OmlFoo createNewFooWithBar(OmlBar bar) {
OmlFoo foo = new OmlFoo();
OmlFoo foo = new OmlFoo(new OmlBaz());
foo.setBar(bar);
OmlBaz baz = new OmlBaz();
baz.setFoo(foo);
foo.getBazList().add(baz);
return foo;
}