mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for #237: find method is returning old entity rather than updated entity in some situations
This commit is contained in:
+7
-7
@@ -2,6 +2,7 @@ package com.avaje.tests.persistencecontext;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
import com.avaje.tests.model.basic.EBasicVer;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,13 +26,12 @@ public class TestPersistenceContextQueryScope extends BaseTestCase {
|
||||
try {
|
||||
EBasicVer bean1 = Ebean.find(EBasicVer.class, bean.getId());
|
||||
|
||||
// do an update of the name
|
||||
EBasicVer updateBean = new EBasicVer();
|
||||
updateBean.setId(bean.getId());
|
||||
updateBean.setName("second");
|
||||
|
||||
// perform an update to the DB
|
||||
Ebean.update(updateBean);
|
||||
// do an update of the name in the DB
|
||||
SqlUpdate sqlUpdate = Ebean.createSqlUpdate("update e_basicver set name=? where id=?");
|
||||
sqlUpdate.setParameter(1, "second");
|
||||
sqlUpdate.setParameter(2, bean.getId());
|
||||
int rowCount = sqlUpdate.execute();
|
||||
assertEquals(1, rowCount);
|
||||
|
||||
// fetch the bean again... but doesn't hit DB as it
|
||||
// is in the PersistenceContext which is transaction scoped
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.avaje.tests.transaction;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.EBasic;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestStatelessUpdateClearPC extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
|
||||
Ebean.beginTransaction();
|
||||
|
||||
EBasic newUser = new EBasic();
|
||||
newUser.setName("any@email.com");
|
||||
Ebean.save(newUser);
|
||||
|
||||
// load the bean into the persistence context
|
||||
EBasic dummyLoadedUser = Ebean.find(EBasic.class, newUser.getId()); // This row is added
|
||||
assertNotNull(dummyLoadedUser);
|
||||
|
||||
// stateless update (should clear the bean from the persistence context)
|
||||
EBasic updateUser = new EBasic();
|
||||
updateUser.setId(newUser.getId());
|
||||
updateUser.setName("anyNew@email.com");
|
||||
Ebean.update(updateUser);
|
||||
|
||||
EBasic loadedUser = Ebean.find(EBasic.class, newUser.getId());
|
||||
assertEquals("anyNew@email.com", loadedUser.getName());
|
||||
|
||||
Ebean.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user