Fix for Issue 72 - Bug - models.Role cannot be cast to java.util.Map [error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveAssocManyDetails(DefaultPersister.java:877)

This commit is contained in:
Rob Bygrave committed 2014-01-23 00:50:09 +13:00
1 parent 87a948223c
commit ee96c4afa6
12 files changed
+169 -22

No files matched your search

@@ -970,11 +970,14 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
public void cachePutMany(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId) {
BeanDescriptor<?> targetDescriptor = many.getTargetDescriptor();
Collection<?> actualDetails = bc.getActualDetails();
ArrayList<Object> idList = new ArrayList<Object>();
// get the underlying collection of beans (in the List, Set or Map)
Collection<?> actualDetails = bc.getActualDetails();
for (Object bean : actualDetails) {
Object id = targetDescriptor.getId(bean);
idList.add(id);
// Collect the id values
idList.add(targetDescriptor.getId(bean));
}
CachedManyIds ids = new CachedManyIds(idList);
cachePutCachedManyIds(parentId, many.getName(), ids);
@@ -38,6 +38,10 @@ public class ManyType {
}
}
public boolean isMap() {
return Underlying.MAP.equals(underlying);
}
/**
* Return the matching Query type.
*/
@@ -788,7 +788,8 @@ public final class DefaultPersister implements Persister {
// check that the list is not null and if it is a BeanCollection
// check that is has been populated (don't trigger lazy loading)
Collection<?> collection = getDetailsIterator(details);
// For a Map this is a collection of Map.Entry objects and not beans
Collection<?> collection = getActualEntries(details);
if (collection == null) {
// nothing to do here
@@ -1262,7 +1263,7 @@ public final class DefaultPersister implements Persister {
* Return the details of the collection or map taking care to avoid
* unnecessary fetching of the data.
*/
private Collection<?> getDetailsIterator(Object o) {
private Collection<?> getActualEntries(Object o) {
if (o == null) {
return null;
}
@@ -1271,7 +1272,9 @@ public final class DefaultPersister implements Persister {
if (!bc.isPopulated()) {
return null;
}
return bc.getActualDetails();
// For maps this is a collection of Map.Entry, otherwise it
// returns a collection of beans
return bc.getActualEntries();
}
if (o instanceof Map<?, ?>) {
@@ -1281,8 +1284,7 @@ public final class DefaultPersister implements Persister {
} else if (o instanceof Collection<?>) {
return ((Collection<?>) o);
}
String m = "expecting a Map or Collection but got [" + o.getClass().getName() + "]";
throw new PersistenceException(m);
throw new PersistenceException("expecting a Map or Collection but got [" + o.getClass().getName() + "]");
}
/**
@@ -83,7 +83,7 @@ public class DefaultOrmQueryEngine implements OrmQueryEngine {
Collection<T> c = result.getActualDetails();
for (T bean : c) {
descriptor.cachePutBeanData(bean);
}
}
}
if (!result.isEmpty() && query.isUseQueryCache()){