java.lang.ClassCastException

Hibernate JIRA | David Tashima | 1 decade ago
  1. 0

    If you attempt to replicate() an object that has a property of type Calendar (calendar_date), you get a ClassCastException. I loathe jumping to conclusions, but I am guessing it is happening on line 54 of CalendarDateType.java, which looks like this: result.setTime( ( (Date) Hibernate.DATE.fromStringValue(xml) ) ); (note that "Date" is java.sql.Date, and the thing that is being created on the right is a java.util.Date). Muchas Gracias -Dave ------------------------------------------------ [java] Hibernate: select id from donut where id =? [java] java.lang.ClassCastException [java] at org.hibernate.type.CalendarDateType.fromStringValue(CalendarDateType.java:54) [java] at org.hibernate.type.NullableType.fromXMLString(NullableType.java:149) [java] at org.hibernate.type.NullableType.fromXMLNode(NullableType.java:173) [java] at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:194) [java] at org.hibernate.property.Dom4jAccessor$Dom4jGetter.getForInsert(Dom4jAccessor.java:9 4) [java] at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntit yTuplizer.java:264) [java] at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(A bstractEntityPersister.java:3328) [java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractS aveEventListener.java:244) [java] at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicate EventListener.java:117) [java] at org.hibernate.impl.SessionImpl.fireReplicate(SessionImpl.java:854) [java] at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:848) [java] at DonutTest.reconstitute(DonutTest.java:57) [java] at DonutTest.main(DonutTest.java:35)

    Hibernate JIRA | 1 decade ago | David Tashima
    java.lang.ClassCastException
  2. 0

    If you attempt to replicate() an object that has a property of type Calendar (calendar_date), you get a ClassCastException. I loathe jumping to conclusions, but I am guessing it is happening on line 54 of CalendarDateType.java, which looks like this: result.setTime( ( (Date) Hibernate.DATE.fromStringValue(xml) ) ); (note that "Date" is java.sql.Date, and the thing that is being created on the right is a java.util.Date). Muchas Gracias -Dave ------------------------------------------------ [java] Hibernate: select id from donut where id =? [java] java.lang.ClassCastException [java] at org.hibernate.type.CalendarDateType.fromStringValue(CalendarDateType.java:54) [java] at org.hibernate.type.NullableType.fromXMLString(NullableType.java:149) [java] at org.hibernate.type.NullableType.fromXMLNode(NullableType.java:173) [java] at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:194) [java] at org.hibernate.property.Dom4jAccessor$Dom4jGetter.getForInsert(Dom4jAccessor.java:9 4) [java] at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntit yTuplizer.java:264) [java] at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(A bstractEntityPersister.java:3328) [java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractS aveEventListener.java:244) [java] at org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicate EventListener.java:117) [java] at org.hibernate.impl.SessionImpl.fireReplicate(SessionImpl.java:854) [java] at org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:848) [java] at DonutTest.reconstitute(DonutTest.java:57) [java] at DonutTest.main(DonutTest.java:35)

    Hibernate JIRA | 1 decade ago | David Tashima
    java.lang.ClassCastException
  3. 0

    I try to save a entity (DOM4J mode) which contains a list: <multiple-choice-task id="1"> ... <choices> <choice id="2"> <task task-ref="1"/> ... </choice> <choice id="3"> <task task-ref="1"/> ... </choice> </choices> </multiple-choice-task> Mappings: <list name="choices" lazy="true" inverse="false" cascade="all-delete-orphan" node="choices"> <key column="taskid" not-null="true"/> <list-index column="index"/> <one-to-many class="....Choice"/> </list> <class name="....Choice" table="choice" node="choice"> <id name="id" column="id" unsaved-value="null" node="@id"> <generator class="hilo"/> </id> <many-to-one name="task" insert="false" update="false" node="task/@task-ref" embed-xml="false"> <column name="taskid" not-null="true"/> </many-to-one> ... </class> If I save the multiple-choice-task with Hibernate 3.1.3 I get following Exception: java.lang.ClassCastException: org.dom4j.tree.DefaultElement at org.hibernate.type.ListType.indexOf(ListType.java:49) at org.hibernate.engine.StatefulPersistenceContext.getIndexInParent(StatefulPersistenceContext.java:1066) at org.hibernate.engine.StatefulPersistenceContext.getIndexInOwner(StatefulPersistenceContext.java:1041) at org.hibernate.property.IndexPropertyAccessor$IndexGetter.getForInsert(IndexPropertyAccessor.java:74) at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:264) at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:3331) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:244) Sourcecode of ListType.indexOf: public Object indexOf(Object collection, Object element) { List list = (List) collection; for ( int i=0; i<list.size(); i++ ) { //TODO: proxies! if ( list.get(i)==element ) return new Integer(i); } return null; } The problem is that the collection is in DOM4J mode a Element with doesn't implement List. In my example collection is the <choices> Element and element is one of the <choice> Elements. I suggest following FIX: public Object indexOf(Object collection, Object element) { if (collection instanceof List) { int index = ((List) collection).indexOf(element); return index == -1 ? null : new Integer(index); } else if (collection instanceof Element) { int index = ((Element) collection).content().indexOf(element); return index == -1 ? null : new Integer(index); } else { throw new IllegalArgumentException("collection type not supported."); } } It works for me. By the way: Why bother with a own for loop and own comparison? Because of equals()? list.get(i) can be much more costly on non RandomAccess lists than an unnessesary equals(). Please fix this issue in the next release. I have to work with the SVN Version and my own fix until than. I have a production system to which I want to add XML backup/restore. Thanks. Alexander Kiel

    Hibernate JIRA | 1 decade ago | Alexander Kiel
    java.lang.ClassCastException: org.dom4j.tree.DefaultElement
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I try to save a entity (DOM4J mode) which contains a list: <multiple-choice-task id="1"> ... <choices> <choice id="2"> <task task-ref="1"/> ... </choice> <choice id="3"> <task task-ref="1"/> ... </choice> </choices> </multiple-choice-task> Mappings: <list name="choices" lazy="true" inverse="false" cascade="all-delete-orphan" node="choices"> <key column="taskid" not-null="true"/> <list-index column="index"/> <one-to-many class="....Choice"/> </list> <class name="....Choice" table="choice" node="choice"> <id name="id" column="id" unsaved-value="null" node="@id"> <generator class="hilo"/> </id> <many-to-one name="task" insert="false" update="false" node="task/@task-ref" embed-xml="false"> <column name="taskid" not-null="true"/> </many-to-one> ... </class> If I save the multiple-choice-task with Hibernate 3.1.3 I get following Exception: java.lang.ClassCastException: org.dom4j.tree.DefaultElement at org.hibernate.type.ListType.indexOf(ListType.java:49) at org.hibernate.engine.StatefulPersistenceContext.getIndexInParent(StatefulPersistenceContext.java:1066) at org.hibernate.engine.StatefulPersistenceContext.getIndexInOwner(StatefulPersistenceContext.java:1041) at org.hibernate.property.IndexPropertyAccessor$IndexGetter.getForInsert(IndexPropertyAccessor.java:74) at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:264) at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:3331) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:244) Sourcecode of ListType.indexOf: public Object indexOf(Object collection, Object element) { List list = (List) collection; for ( int i=0; i<list.size(); i++ ) { //TODO: proxies! if ( list.get(i)==element ) return new Integer(i); } return null; } The problem is that the collection is in DOM4J mode a Element with doesn't implement List. In my example collection is the <choices> Element and element is one of the <choice> Elements. I suggest following FIX: public Object indexOf(Object collection, Object element) { if (collection instanceof List) { int index = ((List) collection).indexOf(element); return index == -1 ? null : new Integer(index); } else if (collection instanceof Element) { int index = ((Element) collection).content().indexOf(element); return index == -1 ? null : new Integer(index); } else { throw new IllegalArgumentException("collection type not supported."); } } It works for me. By the way: Why bother with a own for loop and own comparison? Because of equals()? list.get(i) can be much more costly on non RandomAccess lists than an unnessesary equals(). Please fix this issue in the next release. I have to work with the SVN Version and my own fix until than. I have a production system to which I want to add XML backup/restore. Thanks. Alexander Kiel

    Hibernate JIRA | 1 decade ago | Alexander Kiel
    java.lang.ClassCastException: org.dom4j.tree.DefaultElement
  6. 0

    ClassCastException : PortableRemoteObject.

    Oracle Community | 1 decade ago | 403765
    java.lang.ClassCastException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      No message provided

      at org.hibernate.type.CalendarDateType.fromStringValue()
    2. Hibernate
      AbstractEntityPersister.getPropertyValuesToInsert
      1. org.hibernate.type.CalendarDateType.fromStringValue(CalendarDateType.java:54)
      2. org.hibernate.type.NullableType.fromXMLString(NullableType.java:149)
      3. org.hibernate.type.NullableType.fromXMLNode(NullableType.java:173)
      4. org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:194)
      5. org.hibernate.property.Dom4jAccessor$Dom4jGetter.getForInsert(Dom4jAccessor.java:94)
      6. org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:264)
      7. org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:3328)
      7 frames
    3. Hibernate
      SessionImpl.replicate
      1. org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:244)
      2. org.hibernate.event.def.DefaultReplicateEventListener.onReplicate(DefaultReplicateEventListener.java:117)
      3. org.hibernate.impl.SessionImpl.fireReplicate(SessionImpl.java:854)
      4. org.hibernate.impl.SessionImpl.replicate(SessionImpl.java:848)
      4 frames
    4. Unknown
      DonutTest.main
      1. DonutTest.reconstitute(DonutTest.java:57)
      2. DonutTest.main(DonutTest.java:35)
      2 frames