Merge branch 'master' of https://github.com/ebean-orm/ebean into ebean-new

# Conflicts:
#	ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java
#	ebean-core/src/main/java/io/ebeaninternal/server/deploy/AssocOneHelpRefInherit.java
#	ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java
#	ebean-core/src/main/java/io/ebeaninternal/server/querydefn/OrmQueryPropertiesParser.java
This commit is contained in:
Noemi Szemenyei committed 2021-11-22 08:07:30 +01:00
commit 6ea8f5c12b
7 files changed
+81 -34

No files matched your search

@@ -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());
}
}