mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2184 - Fix for findNative() with fetch() - convert fetch to fetchQuery with nativeSql
When using nativeSql (think of it as the "root query") we can't use "fetch joins" (FetchConfig.ofDefault()) as that means to prefer to use a SQL JOIN. In this nativeSql case we need to effectively automatically convert fetch() to fetchQuery()
This commit is contained in:
@@ -2,6 +2,7 @@ package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FetchConfig;
|
||||
import io.ebean.PagedList;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
@@ -280,7 +281,7 @@ public class TestQueryFindNative extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<Customer> result = DB.findNative(Customer.class, sql)
|
||||
.fetch("contacts")
|
||||
.fetch("contacts", "firstName, lastName")
|
||||
.findList();
|
||||
|
||||
assertThat(result).isNotEmpty();
|
||||
@@ -289,7 +290,7 @@ public class TestQueryFindNative extends BaseTestCase {
|
||||
if (isH2()) {
|
||||
assertThat(loggedSql).hasSize(2);
|
||||
assertThat(loggedSql.get(0)).contains("from o_customer");
|
||||
assertThat(loggedSql.get(1)).contains("from contact");
|
||||
assertThat(loggedSql.get(1)).contains("select t0.customer_id, t0.id, t0.first_name, t0.last_name from contact t0 where");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,8 +329,9 @@ public class TestQueryFindNative extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<Customer> result = DB.findNative(Customer.class, sql)
|
||||
// with nativeSql fetch (default) are converted to fetchQuery()
|
||||
.fetch("orders")
|
||||
.fetch("contacts")
|
||||
.fetch("contacts", FetchConfig.ofDefault())
|
||||
.findList();
|
||||
|
||||
assertThat(result).isNotEmpty();
|
||||
|
||||
Reference in New Issue
Block a user