mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
FIX: When a bean is modified in persistence context and searched again, it will loose the change
This commit is contained in:
1 parent
fa4e013692
commit
d55023dbc7
2 files changed
+24
-10
No files matched your search
@@ -268,9 +268,16 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
|||||||
contextBean = localBean;
|
contextBean = localBean;
|
||||||
} else {
|
} else {
|
||||||
// bean already exists in persistenceContext
|
// bean already exists in persistenceContext
|
||||||
if (isLoadContextBeanNeeded(queryMode, contextBean)) {
|
|
||||||
// refresh it anyway (lazy loading for example)
|
if (queryMode.isLoadContextBean()) {
|
||||||
|
// if explicitly set loadContextBean to true, then reload
|
||||||
localBean = contextBean;
|
localBean = contextBean;
|
||||||
|
} else if (!contextBean._ebean_getIntercept().isFullyLoadedBean()) {
|
||||||
|
// reload if contextBean is partial object
|
||||||
|
localBean = contextBean;
|
||||||
|
// and switch to lazyLoad query mode in order not to overwrite
|
||||||
|
// existing properties in SqlBeanLoad::load
|
||||||
|
queryMode = Mode.LAZYLOAD_BEAN;
|
||||||
} else {
|
} else {
|
||||||
// ignore the DB data...
|
// ignore the DB data...
|
||||||
localBean = null;
|
localBean = null;
|
||||||
@@ -683,14 +690,6 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
|||||||
return "SqlTreeNodeBean: " + desc;
|
return "SqlTreeNodeBean: " + desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLoadContextBeanNeeded(Mode queryMode, EntityBean contextBean) {
|
|
||||||
// if explicitly set loadContextBean to true, then reload
|
|
||||||
if (queryMode.isLoadContextBean()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// reload if contextBean is partial object
|
|
||||||
return !contextBean._ebean_getIntercept().isFullyLoadedBean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasMany() {
|
public boolean hasMany() {
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import io.ebeaninternal.api.SpiPersistenceContext;
|
|||||||
import io.ebeaninternal.api.SpiTransaction;
|
import io.ebeaninternal.api.SpiTransaction;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.tests.model.basic.ContactNote;
|
||||||
import org.tests.model.basic.Customer;
|
import org.tests.model.basic.Customer;
|
||||||
import org.tests.model.basic.Order;
|
import org.tests.model.basic.Order;
|
||||||
import org.tests.model.basic.ResetBasicData;
|
import org.tests.model.basic.ResetBasicData;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -20,6 +22,19 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
class TestPersistenceContext extends BaseTestCase {
|
class TestPersistenceContext extends BaseTestCase {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReload() {
|
||||||
|
ResetBasicData.reset();
|
||||||
|
try (Transaction txn = DB.beginTransaction()) {
|
||||||
|
List<ContactNote> notes = new ArrayList<>();
|
||||||
|
DB.find(ContactNote.class).findEach(notes::add);
|
||||||
|
notes.get(0).setTitle("FooBar");
|
||||||
|
DB.find(ContactNote.class).findList();
|
||||||
|
assertThat(notes.get(0).getTitle()).isEqualTo("FooBar");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test() {
|
void test() {
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|||||||
Reference in new issue
Block a user