[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1265) classcastexception when using dom4jsession to save xml of a versioned class

Jeremiah Marcum (JIRA) noreply at atlassian.com
Thu Nov 2 11:10:05 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1265?page=comments#action_25076 ] 

Jeremiah Marcum commented on HHH-1265:
--------------------------------------

I was also having this problem and was able to fix it by patching the following 2 files:

Note: I changed DirtyCollectionVisitor.java by adding ' || collection instanceof Element' to the if statement.  It may be more appropriate to add ' || !(collection instanceof PersistentCollection) to the if statement so that any collection that needs to be wrapped by its Holder will work instead of just doing that for Elements.

Note2: I had to patch Dom4jAccessor.java because it was returning my id as the actual serializable (Long in my case) and not as an element, which was throwing a CCE.  This may be because my id was specified as an attribute and not as an element, i'm not sure.  Whatever the reason, adding that change fixed it, however it may be better to look further up the line to see what the cause is.

Patch for org.hibernate.event.def.DirtyCollectionSearchVisitor.java
Index: DirtyCollectionSearchVisitor.java
===================================================================
--- DirtyCollectionSearchVisitor.java   (revision 10687)
+++ DirtyCollectionSearchVisitor.java   (working copy)
@@ -37,7 +37,7 @@
                        SessionImplementor session = getSession();

                        final PersistentCollection persistentCollection;
-                       if ( type.isArrayType() ) {
+                       if ( type.isArrayType() || collection instanceof Element ) {
                                 persistentCollection = session.getPersistenceContext().getCollectionHolder(collection);
                                // if no array holder we found an unwrappered array (this can't occur,
                                // because we now always call wrap() before getting to here)

Patch for Dom4jAccessor.java
Index: Dom4jAccessor.java
===================================================================
--- Dom4jAccessor.java  (revision 10687)
+++ Dom4jAccessor.java  (working copy)
@@ -168,6 +168,7 @@
                }

                public Object get(Object owner) throws HibernateException {
+                       if (!(owner instanceof Element)) { return owner; } //EARLY RETURN
                        Element ownerElement = (Element) owner;
                        Node attribute = ownerElement.attribute(attributeName);
                        return attribute==null ? null :


> classcastexception when using dom4jsession to save xml of a versioned class
> ---------------------------------------------------------------------------
>
>          Key: HHH-1265
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1265
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.1, 3.1 beta 2
>  Environment: hibernate 3.1 oracle windows
>     Reporter: Winston Huang
>  Attachments: hibernate_test.zip, patches.zip
>
>
> when importing from xml format and trying to save the instance using dom4jsession, i got the following exception. it would succeed if i don't use an optimistic locking object (with versioning). see the attached test case for details. i have a many-to-many set relationship from user to role. the xml data files are in User.xml and Role.xml. loading Role.xml is fine. but loading User.xml failed. 
> log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
> log4j:WARN Please initialize the log4j system properly.
> Exception in thread "main" java.lang.ClassCastException: org.dom4j.tree.DefaultElement
> 	at org.hibernate.event.def.DirtyCollectionSearchVisitor.processCollection(DirtyCollectionSearchVisitor.java:50)
> 	at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
> 	at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
> 	at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
> 	at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:301)
> 	at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:111)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
> 	at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
> 	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
> 	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
> 	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:329)
> 	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
> 	at TestDom4jVersionedObject.main(TestDom4jVersionedObject.java:26)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list