Assume InfoInherit infoType when it has no children

This commit is contained in:
Noemi Szemenyei committed 2021-11-16 13:44:53 +01:00
1 parent 5807874c9e
commit 1c224444c0
4 files changed
+41 -6

No files matched your search

@@ -4,7 +4,6 @@ import javax.persistence.Entity;
import javax.persistence.Inheritance;
@Entity
@Inheritance
public class Target1 extends TargetBase {
public Target1(String name) {
@@ -3,6 +3,9 @@ package org.tests.lazyforeignkeys;
import io.ebean.annotation.DbForeignKey;
import javax.persistence.*;
import org.tests.model.basic.Cat;
import java.util.UUID;
@@ -22,6 +25,11 @@ public class MainEntityRelation {
@JoinColumn(name = "id2")
@DbForeignKey(noConstraint = true)
private MainEntity entity2;
@ManyToOne
@JoinColumn(name = "cat_id")
@DbForeignKey(noConstraint = true)
private Cat cat;
private String attr1;
@@ -41,6 +49,14 @@ public class MainEntityRelation {
this.entity2 = entity2;
}
public Cat getCat() {
return cat;
}
public void setCat(Cat cat) {
this.cat = cat;
}
public String getAttr1() {
return attr1;
}
@@ -8,6 +8,7 @@ import io.ebean.text.PathProperties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Cat;
import java.util.List;
@@ -56,7 +57,7 @@ public class TestLazyForeignKeys extends BaseTestCase {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(3);
assertSql(sql.get(0)).contains("select t0.id, t0.attr1, t0.id1, t0.id2 from main_entity_relation");
assertSql(sql.get(0)).contains("select t0.id, t0.attr1, t0.id1, t0.id2, t1.species, t0.cat_id from main_entity_relation t0 left join animal t1 on t1.id = t0.cat_id");
if (isSqlServer() || isOracle()) {
assertSql(sql.get(1)).contains("select t0.id, t0.attr1, t0.attr2, CASE WHEN t0.id is null THEN 1 ELSE 0 END from main_entity t0");
} else {
@@ -86,4 +87,17 @@ public class TestLazyForeignKeys extends BaseTestCase {
assertFalse(rel1.getEntity1().isDeleted());
assertTrue(rel1.getEntity2().isDeleted());
}
@Test
public void testGetWithDbForeignKey() {
MainEntityRelation relation = DB.find(MainEntityRelation.class).findOne();
Cat cat = new Cat();
cat.setId(123L);
relation.setCat(cat);
DB.save(relation);
relation = DB.find(MainEntityRelation.class).findOne();
assertNotNull(relation.getCat());
}
}