Hybris:产品驾驶舱在集合的比较模式下抛出ClassCastException。在正常模式下,它工作正常。
如何将MyTypedObject显式转换为集合?
我的代码段:
Collection<CategoryModel> pCategories = ProductModel.getSupercategories();
for (CategoryModel parentCategory : pCategories) { //ClassCastExceptionthrown
//do something
} }
堆栈跟踪:
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | java.lang.ClassCastException: de.hybris.platform.cockpit.services.meta.impl.ExtensibleTypeService$MyTypedObject cannot be cast to de.hybris.platform.category.model.CategoryModel
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at com.org.comm.hybris.core.servicelayer.attributehandlers.DynamicTSCategoryHandler.get(DynamicTSCategoryHandler.java:42)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at com.org.comm.hybris.core.servicelayer.attributehandlers.DynamicTSCategoryHandler.get(DynamicTSCategoryHandler.java:1)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at de.hybris.platform.servicelayer.internal.model.attribute.impl.DefaultDynamicAttributesProvider.get(DefaultDynamicAttributesProvider.java:48)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at de.hybris.platform.servicelayer.model.ItemModelContextImpl.getDynamicValue(ItemModelContextImpl.java:281)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at com.org.comm.hybris.core.model.ProductModel.getMyTSSuperCategory(ProductModel.java:1669)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at java.lang.reflect.Method.invoke(Method.java:606)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:196)
INFO | jvm 1 | main | 2016/05/10 09:28:19.464 | at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:181)
答案 0 :(得分:0)
从特定的产品中查看HMC,它具有完全超类别。据我所知,超类别不必总是来自 CategoryModel 类型。您似乎已使用 MyTypedObject 扩展了 CategoryModel 。
以前你必须在这里做检查。类似的东西:
if (parentCategory instanceof ...)