mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 10:03:59 +00:00
FIX: do not hit database if inherited entity has no children (#974)
* FIX: do not hit database if inherited entity has no children * ADD: Testcase for creating references of inherited beans
This commit is contained in:
committed by
Rob Bygrave
parent
7632910027
commit
40ca179509
@@ -612,7 +612,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
|
||||
InheritInfo inheritInfo = desc.getInheritInfo();
|
||||
if (inheritInfo == null) {
|
||||
if (inheritInfo == null || inheritInfo.getChildren().isEmpty()) {
|
||||
return (T) desc.contextRef(pc, null, false, id);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,14 @@ public class InheritInfo {
|
||||
public BeanProperty[] localProperties() {
|
||||
return descriptor.propertiesLocal();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the children.
|
||||
*/
|
||||
public ArrayList<InheritInfo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bean property additionally looking in the sub types.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.inheritance;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.avaje.ebeantest.LoggedSqlCollector;
|
||||
import org.avaje.test.model.rawsql.inherit.ChildA;
|
||||
import org.avaje.test.model.rawsql.inherit.ChildB;
|
||||
import org.avaje.test.model.rawsql.inherit.Parent;
|
||||
import org.junit.Test;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
|
||||
public class TestInheritanceRefBean extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Parent a = new ChildA(42, "Bean A");
|
||||
Parent b = new ChildB(43, "Bean B");
|
||||
|
||||
server().save(a);
|
||||
server().save(b);
|
||||
Long idA = a.getId();
|
||||
Long idB = b.getId();
|
||||
|
||||
Parent test;
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
test = server().getReference(ChildA.class, idA);
|
||||
assertTrue(test instanceof ChildA);
|
||||
assertEquals(0, LoggedSqlCollector.stop().size());
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
test = server().getReference(Parent.class, idB);
|
||||
assertTrue(test instanceof ChildB);
|
||||
assertEquals(1, LoggedSqlCollector.stop().size());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user