diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index 73765d43d..09851725f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -226,7 +226,7 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc implements ST */ @Override public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean, boolean withCheck) { - BeanCollection bc = (BeanCollection) super.getValue(parentBean); + BeanCollection bc = beanCollection(parentBean); if (bc == null) { bc = help.createEmpty(parentBean); setValue(parentBean, bc); @@ -234,6 +234,15 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc implements ST help.add(bc, detailBean, withCheck); } + private BeanCollection beanCollection(EntityBean parentBean) { + try { + return (BeanCollection) super.getValue(parentBean); + } catch (ClassCastException e) { + // fetching element collection, ok for now + return null; + } + } + /** * Return true if this is considered 'empty' from a save perspective. */