-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #3381 - Empty OneToMany when overflowing LazyLoadBatchSize an…
…d mixed queries 14.0.0 via #3295 introduced this bug. #3295 introduced a behaviour where bulk updates clear the persistence context. Now the lazy loading of a BeanCollection works with an assumption that the "parent bean" is in the persistence context (and this assumption is broken with that change for this test case). That is, the bulk update is clearing the persistence context - removing the parent bean BEFORE the lazy loading is invoked ... and that doesn't then work because the parent bean isn't in the persistence context. This fix means that when lazy loading many's, the parent beans are putIfAbsent into the persistence context.
- Loading branch information
Showing
7 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
ebean-test/src/test/java/org/tests/cascade/TestLazyLoadMany.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.tests.cascade; | ||
|
||
import io.ebean.DB; | ||
import io.ebean.Transaction; | ||
import io.ebean.xtest.BaseTestCase; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class TestLazyLoadMany extends BaseTestCase { | ||
|
||
COOne create(String parentName, int childCount) { | ||
COOne m0 = new COOne(parentName); | ||
for (int i = 0; i < childCount; i++) { | ||
m0.getChildren().add(new COOneMany(parentName+"_"+i)); | ||
} | ||
return m0; | ||
} | ||
@Test | ||
void loadAfterPCCleared() { | ||
|
||
var m0 = create("tll-m0", 2); | ||
var m1 = create("tll-m1", 4); | ||
var m2 = create("tll-m2", 5); | ||
|
||
DB.saveAll(m0, m1, m2); | ||
|
||
try (Transaction transaction = DB.beginTransaction()) { | ||
List<COOne> children = DB.find(COOne.class) | ||
.setLazyLoadBatchSize(2) | ||
.where().startsWith("name", "tll-m") | ||
.findList(); | ||
|
||
assertThat(children).hasSize(3); | ||
assertThat(children.get(0).getChildren()).describedAs("invoke lazy loading on children").hasSize(2); | ||
|
||
DB.sqlUpdate("update coone set name = ? where id = ?") | ||
.setParameters("new name", children.get(0).getId()) | ||
.executeNow(); // clears the persistence context in 14.0.0+ due to #3295 #3301 | ||
|
||
// the children here were already lazy loaded | ||
assertThat(children.get(1).getChildren()).hasSize(4); | ||
// this invokes the lazy loading of children AFTER the persistence context was cleared | ||
assertThat(children.get(2).getChildren()).hasSize(5); | ||
|
||
transaction.rollback(); | ||
} finally { | ||
DB.deleteAll(List.of(m0, m1, m2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters