Cascade.cascadeCollectionElements ClastCastException for non-entity element types
Description
When trying to flush changes in EntityMode.DOM4J, a composite element causes a ClassCastException in Cascade.cascadeCollectionElements when invoked by Cascade.cascadeCollection. The latter allows the call to the former when the element is of ComponentType, but assumes in the former always casts to EntityType if EntityMode.DOM4J is in effect.
When trying to flush changes in EntityMode.DOM4J, a composite element causes a ClassCastException in Cascade.cascadeCollectionElements when invoked by Cascade.cascadeCollection. The latter allows the call to the former when the element is of ComponentType, but assumes in the former always casts to EntityType if EntityMode.DOM4J is in effect.
Possible patch:
diff -u -r1.1 Cascade.java
— src/org/hibernate/engine/Cascade.java 3 Jul 2007 20:12:01 -0000 1.1
+++ src/org/hibernate/engine/Cascade.java 30 Jul 2007 19:42:54 -0000
@@ -281,7 +281,7 @@
final boolean isCascadeDeleteEnabled) throws HibernateException {
// we can't cascade to non-embedded elements
boolean embeddedElements = eventSource.getEntityMode()!=EntityMode.DOM4J ||
- ( (EntityType) collectionType.getElementType( eventSource.getFactory() ) ).isEmbeddedInXML();
+ ( elemType.isEntityType() && ( (EntityType) elemType ).isEmbeddedInXML() );
boolean reallyDoCascade = style.reallyDoCascade(action) &&
embeddedElements && child!=CollectionType.UNFETCHED_COLLECTION;