#2748 - Fix partially loaded bean scenario with .setDisableLazyLoading(true) .setBeanCacheMode(CacheMode.PUT) // force query to hit database

This commit is contained in:
Rob Bygrave
2022-07-20 08:16:43 +12:00
parent 48404fc85d
commit ac1e1757e8
3 changed files with 46 additions and 2 deletions
@@ -365,7 +365,7 @@ class SqlTreeLoadBean implements SqlTreeLoad {
* context we need to check if it is already contained in the collection.
*/
final boolean isContextBean() {
return localBean == null;
return localBean == null || queryMode == Mode.LAZYLOAD_BEAN;
}
}
@@ -11,8 +11,25 @@ public class OMVertexOther {
private UUID id;
private final String name;
private String other;
public OMVertexOther(String name) {
this.name = name;
}
public UUID getId() {
return id;
}
public String getName() {
return name;
}
public String getOther() {
return other;
}
public void setOther(String other) {
this.other = other;
}
}
@@ -29,7 +29,34 @@ class TestOneToManyDuplicateInTxn {
OMVertex second = DB.find(OMVertex.class)
//.setLoadBeanCache(true)
.setBeanCacheMode(CacheMode.PUT)
.setBeanCacheMode(CacheMode.PUT) // force query to hit database
.setDisableLazyLoading(true)
.fetch("related")
.where().eq("id", master.getId())
.findOne();
assertThat(second.getRelated()).hasSize(1);
}
}
@Test
void findTwice_partial() {
OMVertex master = new OMVertex(UUID.randomUUID());
OMVertexOther child = new OMVertexOther("child");
master.getRelated().add(child);
DB.save(master);
try (Transaction txn = DB.beginTransaction()) {
OMVertex first = DB.find(OMVertex.class)
.setDisableLazyLoading(true)
.fetch("related", "name") // load a partially loaded bean
.where().eq("id", master.getId())
.findOne();
assertThat(first.getRelated()).hasSize(1);
OMVertex second = DB.find(OMVertex.class)
.setBeanCacheMode(CacheMode.PUT) // force query to hit database
.setDisableLazyLoading(true)
.fetch("related")
.where().eq("id", master.getId())