mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
For #2038 - updated from 12.3.6 to 12.3.7 - NPE BeanDescriptor.findPropertyFromPath(BeanDescriptor.java:1965) (#2047)
* #2038 - lazy loading ToMany with path * #2038 - Failing test for NPE BeanDescriptor.findPropertyFromPath(BeanDescriptor.java:1965) * #2038 Refactor internals DbReadContext use BeanPropertyAssocMany
This commit is contained in:
@@ -5,6 +5,7 @@ import io.ebean.FetchConfig;
|
||||
import io.ebean.Query;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequestTestHelper;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -94,13 +95,14 @@ public class DLoadContextTest extends BaseTestCase {
|
||||
@Test
|
||||
public void construct_when_fetch_expect_100_100_batchSize() {
|
||||
|
||||
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>)getBeanDescriptor(Order.class).getBeanProperty("details");
|
||||
// the fetch is converted to a query join due to the maxRows
|
||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetch("details").setMaxRows(100));
|
||||
queryRequest.initTransIfRequired();
|
||||
queryRequest.endTransIfRequired();
|
||||
|
||||
DLoadContext graphContext = (DLoadContext) queryRequest.getGraphContext();
|
||||
DLoadManyContext details = graphContext.getManyContext("details");
|
||||
DLoadManyContext details = graphContext.getManyContext("details", many);
|
||||
|
||||
assertThat(details.firstBatchSize).isEqualTo(100);
|
||||
assertThat(details.secondaryBatchSize).isEqualTo(100);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.tests.o2m.lazy;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "oml_bar")
|
||||
public class OmlBar {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@OneToMany(mappedBy = "bar", cascade = CascadeType.ALL)
|
||||
private List<OmlFoo> fooList = new ArrayList<OmlFoo>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<OmlFoo> getFooList() {
|
||||
return fooList;
|
||||
}
|
||||
|
||||
public void setFooList(List<OmlFoo> fooList) {
|
||||
this.fooList = fooList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.tests.o2m.lazy;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "oml_baz")
|
||||
public class OmlBaz {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
private OmlFoo foo;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OmlFoo getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(OmlFoo foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.tests.o2m.lazy;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "oml_foo")
|
||||
public class OmlFoo {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
private OmlBar bar;
|
||||
|
||||
@OneToMany(mappedBy = "foo", cascade = CascadeType.ALL)
|
||||
private List<OmlBaz> bazList = new ArrayList<OmlBaz>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public OmlBar getBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
public void setBar(OmlBar bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
public List<OmlBaz> getBazList() {
|
||||
return bazList;
|
||||
}
|
||||
|
||||
public void setBazList(List<OmlBaz> bazList) {
|
||||
this.bazList = bazList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.tests.o2m.lazy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
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);
|
||||
|
||||
OmlFoo fooFromDb = DB
|
||||
.find(OmlFoo.class)
|
||||
.where()
|
||||
.eq("id", bar.getFooList().get(0).getId())
|
||||
.findOne();
|
||||
|
||||
// This works
|
||||
List<OmlFoo> foosList = fooFromDb.getBar().getFooList();
|
||||
assertThat(fooList.size()).isEqualTo(1);
|
||||
|
||||
OmlBaz bazFromDb = DB
|
||||
.find(OmlBaz.class)
|
||||
.where()
|
||||
.eq("id", bar.getFooList().get(0).getBazList().get(0).getId())
|
||||
.findOne();
|
||||
|
||||
// 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();
|
||||
foo.setBar(bar);
|
||||
OmlBaz baz = new OmlBaz();
|
||||
baz.setFoo(foo);
|
||||
foo.getBazList().add(baz);
|
||||
return foo;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user