mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2748 - Fix partially loaded bean scenario with .setDisableLazyLoading(true) .setBeanCacheMode(CacheMode.PUT) // force query to hit database
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user