mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - add a new test for OneToOne with fetchType LAZY
This commit is contained in:
@@ -2,6 +2,7 @@ package org.tests.model.onetoone;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class OtoBMaster {
|
||||
|
||||
String name;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, mappedBy = "master")
|
||||
@OneToOne(cascade = CascadeType.ALL, mappedBy = "master", fetch = FetchType.LAZY)
|
||||
OtoBChild child;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -3,12 +3,53 @@ package org.tests.model.onetoone;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.Query;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestOneToOneImportedPkNative extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void findWithLazyOneToOne() {
|
||||
|
||||
OtoBChild child = new OtoBChild();
|
||||
child.setChild("c1");
|
||||
|
||||
OtoBMaster master = new OtoBMaster();
|
||||
master.setName("m2");
|
||||
master.setChild(child);
|
||||
|
||||
Ebean.save(master);
|
||||
|
||||
Query<OtoBMaster> query = Ebean.find(OtoBMaster.class)
|
||||
//.select("name")
|
||||
.where().idEq(master.getId())
|
||||
.query();
|
||||
|
||||
OtoBMaster one = query.findOne();
|
||||
|
||||
String sql = sqlOf(query);
|
||||
assertThat(sql).contains("select t0.id, t0.name from oto_bmaster t0 where t0.id ");
|
||||
assertThat(sql).doesNotContain("left join oto_bchild");
|
||||
|
||||
assertThat(one).isNotNull();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
OtoBChild child1 = one.getChild();
|
||||
assertThat(child1).isNotNull();
|
||||
assertThat(child1.getChild()).isEqualTo("c1");
|
||||
|
||||
List<String> lazyLoadSql = LoggedSqlCollector.stop();
|
||||
assertThat(lazyLoadSql).hasSize(2);
|
||||
assertThat(lazyLoadSql.get(0)).contains("select t0.id, t0.name, t1.master_id from oto_bmaster t0 left join oto_bchild t1");
|
||||
assertThat(lazyLoadSql.get(1)).contains("select t0.master_id, t0.child, t0.master_id from oto_bchild t0 where t0.master_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void native_with_o2oAndImportedPrimaryKey() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user