mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 23:56:36 +00:00
Fix for #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:
@@ -10,6 +10,7 @@ import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.*;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
@@ -151,6 +152,14 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
|
||||
return persistenceContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the bean to the persistence context.
|
||||
*/
|
||||
public void persistenceContextAdd(EntityBean bean) {
|
||||
Object id = beanDescriptor.getId(bean);
|
||||
persistenceContext.put(id, bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will create a local (readOnly) transaction if no current transaction
|
||||
* exists.
|
||||
|
||||
@@ -433,6 +433,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
} else {
|
||||
// nextBean set to previously read currentBean
|
||||
nextBean = currentBean;
|
||||
request.persistenceContextAdd(nextBean);
|
||||
// check the current row we have just moved to
|
||||
if (checkForDifferentBean()) {
|
||||
return true;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TestOneToManyCorrectGrouping extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> customerQuery = Ebean.find(Customer.class)
|
||||
.fetch("orders")
|
||||
.where()
|
||||
.where().le("id", 2)
|
||||
.query();
|
||||
|
||||
QueryIterator<Customer> customerQueryIterator = customerQuery.findIterate();
|
||||
|
||||
Reference in New Issue
Block a user