mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: correct caching when collection with different inherited beans is put to the cache (#1379)
* FIX: correct cahcing when collection with different inherited beans is put to the cache * removed some sysouts
This commit is contained in:
committed by
Rob Bygrave
parent
d1b7b082a2
commit
ab301f970c
@@ -4,10 +4,14 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import org.tests.model.basic.cache.CInhOne;
|
||||
import org.tests.model.basic.cache.CInhRef;
|
||||
import org.tests.model.basic.cache.CInhRoot;
|
||||
import org.tests.model.basic.cache.CInhTwo;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
@@ -61,4 +65,47 @@ public class TestInheritanceRefCache extends BaseTestCase {
|
||||
assertThat(sql).hasSize(0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
|
||||
CInhOne one = new CInhOne();
|
||||
one.setLicenseNumber("O19");
|
||||
one.setDriver("Foo");
|
||||
one.setNotes("Hello");
|
||||
Ebean.save(one);
|
||||
|
||||
ids.add(one.getId());
|
||||
|
||||
CInhTwo two = new CInhTwo();
|
||||
two.setLicenseNumber("T23");
|
||||
two.setAction("Test");
|
||||
Ebean.save(two);
|
||||
|
||||
ids.add(two.getId());
|
||||
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(CInhRoot.class).setUseQueryCache(true).where().idIn(ids).setMapKey("licenseNumber").findMap();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("from cinh_root");
|
||||
|
||||
// try some cache finds
|
||||
Ebean.find(CInhRoot.class).setUseQueryCache(true).findList();
|
||||
Ebean.find(CInhRoot.class).setUseQueryCache(true).findList();
|
||||
Ebean.find(CInhRoot.class).setUseQueryCache(true).findList();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(CInhRoot.class).setUseQueryCache(true).where().idIn(ids).setMapKey("licenseNumber").findMap();
|
||||
|
||||
sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@Cache
|
||||
@Cache(enableQueryCache = true)
|
||||
@Entity
|
||||
@Inheritance
|
||||
@DiscriminatorColumn(length = 3)
|
||||
|
||||
Reference in New Issue
Block a user