Test case for #75 - Persistence Context Cache not cleared when updating an entity in a running transaction. Actually the test case does not fail.

This commit is contained in:
Rob Bygrave
2014-04-27 00:05:00 +12:00
parent 1a13fc9742
commit dde59db411
2 changed files with 52 additions and 1 deletions
@@ -0,0 +1,44 @@
package com.avaje.tests.persistencecontext;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.tests.model.basic.EBasic;
public class TestPersistenceContextOnUpdateDuringTxn extends BaseTestCase {
@Test
public void test() {
EbeanServer server = Ebean.getServer(null);
server.beginTransaction();
try {
EBasic bean1 = new EBasic();
bean1.setName("hello");
server.save(bean1);
EBasic updatedEntity = new EBasic();
updatedEntity.setId(bean1.getId());
updatedEntity.setName("hello-changed");
server.update(updatedEntity);
// actually the bean is not in the persistence context so ... the assert is fine
EBasic loadedEntity = server.find(EBasic.class,bean1.getId());
assertThat(loadedEntity.getName(), is("hello-changed"));
} finally {
server.endTransaction();
}
}
}