mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#425 - Extra instance of root level bean with findIterate() and fetch of OneToMany relationship - Ebean parses the first bean correctly and the rest not
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.QueryIterator;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestOneToManyCorrectGrouping extends BaseTestCase {
|
||||
|
||||
public static final int EXPECTED_ITERATIONS = 2;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> customerQuery = Ebean.find(Customer.class)
|
||||
.fetch("orders")
|
||||
.where()
|
||||
.query();
|
||||
|
||||
QueryIterator<Customer> customerQueryIterator = customerQuery.findIterate();
|
||||
|
||||
try {
|
||||
int count = 0;
|
||||
while (customerQueryIterator.hasNext()) {
|
||||
Customer customer = customerQueryIterator.next();
|
||||
System.out.println(String.format("Customer id %s", customer.getId()));
|
||||
for (Order order : customer.getOrders()) {
|
||||
System.out.println(String.format("--> Order id %s", order.getId()));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
assertEquals(EXPECTED_ITERATIONS, count);
|
||||
|
||||
} finally {
|
||||
customerQueryIterator.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user