mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
findMap() with beanCache should use idPoperty if mapKey = null
This commit is contained in:
@@ -570,7 +570,12 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
||||
}
|
||||
|
||||
private ElPropertyValue mapProperty() {
|
||||
ElPropertyValue property = beanDescriptor.elGetValue(query.getMapKey());
|
||||
ElPropertyValue property;
|
||||
if (query.getMapKey() == null) {
|
||||
property = beanDescriptor.idProperty();
|
||||
} else {
|
||||
property = beanDescriptor.elGetValue(query.getMapKey());
|
||||
}
|
||||
if (property == null) {
|
||||
throw new IllegalStateException("Unknown map key property " + query.getMapKey());
|
||||
}
|
||||
|
||||
@@ -2,12 +2,18 @@ package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestLoadBeanCache extends BaseTestCase {
|
||||
@@ -31,4 +37,30 @@ public class TestLoadBeanCache extends BaseTestCase {
|
||||
|
||||
assertTrue(loadedNz == nz);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadWithFindMap() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> ids = DB.find(Customer.class).findIds();
|
||||
assertEquals(ids.size(), 4);
|
||||
|
||||
DB.getDefault().pluginApi().cacheManager().clearAll();
|
||||
|
||||
// hit database
|
||||
LoggedSql.start();
|
||||
DB.find(Customer.class).where().idIn(ids).findMap();
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
|
||||
// hit beanCache
|
||||
LoggedSql.start();
|
||||
DB.find(Customer.class).where().idIn(ids).findMap();
|
||||
sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user