Hi
In version 7.1.1, I was in specific context that shows a bug in (little) bug in com.haulmont.cuba.core.global.MetadataTools#deepCopy line 1149
I use a DataGrid component that displays entities “Order” (based on BaseIntIdentityIdEntity ).
Order contains a property “customer” (entity Customer based on BaseIntIdentityIdEntity too) and other properties
When I edit a cell in the DataGrid and then validate the modification, I have an exception.
java.lang.ClassCastException: com..mycompany....Order cannot be cast to com..mycompany.....Customer at com.haulmont.chile.core.model.impl.AbstractInstance.setValue(AbstractInstance.java:132)
at com.haulmont.cuba.core.entity.BaseGenericIdEntity.setValue(BaseGenericIdEntity.java:126)
at com.haulmont.chile.core.model.impl.AbstractInstance.setValue(AbstractInstance.java:114)
at com.haulmont.cuba.core.global.MetadataTools.deepCopy(MetadataTools.java:1152)
at com.haulmont.cuba.core.global.MetadataTools.deepCopy(MetadataTools.java:1104)
I found the reason why :
- it was due to the fact that my “order.id” was equals to customer.id (integer value) in my test data.
May be in the following code (from line 1146 in MetadataTools.java), the “if” condition may include a test on the class.
Entity srcRef = (Entity) value;
Entity reloadedRef = entitiesHolder.find(srcRef.getId()); <<<< in my case, returns the Order instead of the Customer
if (reloadedRef == null) { <<<< may add a test on class
reloadedRef = entitiesHolder.create(srcRef.getClass(), srcRef.getId());
deepCopy(srcRef, reloadedRef, entitiesHolder);
}
destination.setValue(name, reloadedRef);
May be line 1138 should be checked too … and other locations ?
regards,
Guillaume