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:
Roland Praml
2018-05-20 16:53:56 +12:00
committed by Rob Bygrave
parent d1b7b082a2
commit ab301f970c
3 changed files with 63 additions and 2 deletions
@@ -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
View File
@@ -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)