java.lang.ClassCastException: org.dom4j.tree.DefaultElement

Hibernate JIRA | Martin Caslavsky | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    import java.util.Set; public class TestA implements java.io.Serializable { private int a_id; private String testa; private Set b; public TestA() { } public int getA_id() { return this.a_id; } public void setA_id(int a_id) { this.a_id = a_id; } public String getTesta() { return this.testa; } public void setTesta(String testa) { this.testa = testa; } public Set getB() { return this.b; } public void setB(Set b) { this.b = b; } } public class TestB implements java.io.Serializable { private int b_id; private int ref_a; private String testb; public TestB() { } public int getB_id() { return this.b_id; } public void setB_id(int b_id) { this.b_id = b_id; } public int getRef_a() { return this.ref_a; } public void setRef_a(int ref_a) { this.ref_a = ref_a; } public String getTestb() { return this.testb; } public void setTestb(String testb) { this.testb = testb; } public String toString() { return b_id + ": " + testb; } public boolean equals(Object o) { if (!(o instanceof TestB)) return false; if ((b_id == ((TestB)o).getB_id()) && (ref_a == ((TestB)o).getRef_a())) return true; else return false; } } <hibernate-mapping > <class name="TestA" table="testa" node="testa"> <id name="a_id" type="int" unsaved-value="any" column="a_id" node="@a_id"/> <property name="testa" column="testa" node="testa"/> <set name="b" node="testb" embed-xml="true"> <key column="ref_a"/> <one-to-many class="TestB"/> </set> </class> </hibernate-mapping> <hibernate-mapping> <class name="TestB" table="testb"> <composite-id> <key-property name="b_id" type="int" column="b_id"/> <key-property name="ref_a" column="ref_a"/> </composite-id> <property name="testb" column="testb" node="testb"/> </class> </hibernate-mapping> import org.hibernate.cfg.Configuration; import org.hibernate.*; import org.dom4j.*; import org.dom4j.io.*; import java.util.*; public class Main { public Main() { } public static void main(String[] args) { Configuration cfg = new Configuration() .addClass(TestA.class) .addClass(TestB.class); SessionFactory factory = cfg.buildSessionFactory(); Session session4 = factory.openSession().getSession(EntityMode.DOM4J); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("testa"); Query query = session4.createQuery("from TestA as a"); for (Iterator it = query.iterate(); it.hasNext();) { Element e = (Element) it.next(); root.add(e); //TestA t = (TestA) it.next(); //System.out.println(t.getA_id()+t.getB().toString()); } } } Exception in thread "main" java.lang.ClassCastException: org.dom4j.tree.DefaultElement at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:279) at org.hibernate.pretty.MessageHelper.infoString(MessageHelper.java:68) at org.hibernate.engine.EntityKey.toString(EntityKey.java:77) at java.lang.String.valueOf(String.java:2577) at java.lang.StringBuffer.append(StringBuffer.java:220) at org.hibernate.util.StringHelper.toString(StringHelper.java:168) at org.hibernate.loader.Loader.getRow(Loader.java:762) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:295) at org.hibernate.loader.Loader.doQuery(Loader.java:389) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208) at org.hibernate.loader.Loader.loadCollection(Loader.java:1367) at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:107) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1356) at org.hibernate.type.CollectionType.getCollection(CollectionType.java:470) at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:328) at org.hibernate.type.CollectionType.resolve(CollectionType.java:322) at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:494) at org.hibernate.loader.Loader.doQuery(Loader.java:413) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208) at org.hibernate.loader.Loader.loadEntity(Loader.java:1278) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126) at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2491) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:386) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:367) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:119) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:593) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80) at org.hibernate.proxy.Dom4jLazyInitializer.getElement(Dom4jLazyInitializer.java:21) at org.hibernate.proxy.Dom4jProxy.target(Dom4jProxy.java:561) at org.hibernate.proxy.Dom4jProxy.getParent(Dom4jProxy.java:177) at org.dom4j.tree.AbstractElement.addNode(AbstractElement.java:2130) at org.dom4j.tree.AbstractElement.add(AbstractElement.java:1412) at Main.main(Main.java:27) Fetching data with default EntityMode (now commented out in class Main) works fine. (Tried also with H3 from CVS. Posted to forum, but no response in a week, so suppose to be a bug.)

    Hibernate JIRA | 1 decade ago | Martin Caslavsky
    java.lang.ClassCastException: org.dom4j.tree.DefaultElement
  2. 0

    import java.util.Set; public class TestA implements java.io.Serializable { private int a_id; private String testa; private Set b; public TestA() { } public int getA_id() { return this.a_id; } public void setA_id(int a_id) { this.a_id = a_id; } public String getTesta() { return this.testa; } public void setTesta(String testa) { this.testa = testa; } public Set getB() { return this.b; } public void setB(Set b) { this.b = b; } } public class TestB implements java.io.Serializable { private int b_id; private int ref_a; private String testb; public TestB() { } public int getB_id() { return this.b_id; } public void setB_id(int b_id) { this.b_id = b_id; } public int getRef_a() { return this.ref_a; } public void setRef_a(int ref_a) { this.ref_a = ref_a; } public String getTestb() { return this.testb; } public void setTestb(String testb) { this.testb = testb; } public String toString() { return b_id + ": " + testb; } public boolean equals(Object o) { if (!(o instanceof TestB)) return false; if ((b_id == ((TestB)o).getB_id()) && (ref_a == ((TestB)o).getRef_a())) return true; else return false; } } <hibernate-mapping > <class name="TestA" table="testa" node="testa"> <id name="a_id" type="int" unsaved-value="any" column="a_id" node="@a_id"/> <property name="testa" column="testa" node="testa"/> <set name="b" node="testb" embed-xml="true"> <key column="ref_a"/> <one-to-many class="TestB"/> </set> </class> </hibernate-mapping> <hibernate-mapping> <class name="TestB" table="testb"> <composite-id> <key-property name="b_id" type="int" column="b_id"/> <key-property name="ref_a" column="ref_a"/> </composite-id> <property name="testb" column="testb" node="testb"/> </class> </hibernate-mapping> import org.hibernate.cfg.Configuration; import org.hibernate.*; import org.dom4j.*; import org.dom4j.io.*; import java.util.*; public class Main { public Main() { } public static void main(String[] args) { Configuration cfg = new Configuration() .addClass(TestA.class) .addClass(TestB.class); SessionFactory factory = cfg.buildSessionFactory(); Session session4 = factory.openSession().getSession(EntityMode.DOM4J); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("testa"); Query query = session4.createQuery("from TestA as a"); for (Iterator it = query.iterate(); it.hasNext();) { Element e = (Element) it.next(); root.add(e); //TestA t = (TestA) it.next(); //System.out.println(t.getA_id()+t.getB().toString()); } } } Exception in thread "main" java.lang.ClassCastException: org.dom4j.tree.DefaultElement at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:279) at org.hibernate.pretty.MessageHelper.infoString(MessageHelper.java:68) at org.hibernate.engine.EntityKey.toString(EntityKey.java:77) at java.lang.String.valueOf(String.java:2577) at java.lang.StringBuffer.append(StringBuffer.java:220) at org.hibernate.util.StringHelper.toString(StringHelper.java:168) at org.hibernate.loader.Loader.getRow(Loader.java:762) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:295) at org.hibernate.loader.Loader.doQuery(Loader.java:389) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208) at org.hibernate.loader.Loader.loadCollection(Loader.java:1367) at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:107) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1356) at org.hibernate.type.CollectionType.getCollection(CollectionType.java:470) at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:328) at org.hibernate.type.CollectionType.resolve(CollectionType.java:322) at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:494) at org.hibernate.loader.Loader.doQuery(Loader.java:413) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208) at org.hibernate.loader.Loader.loadEntity(Loader.java:1278) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141) at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126) at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2491) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:386) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:367) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:119) at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:593) at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80) at org.hibernate.proxy.Dom4jLazyInitializer.getElement(Dom4jLazyInitializer.java:21) at org.hibernate.proxy.Dom4jProxy.target(Dom4jProxy.java:561) at org.hibernate.proxy.Dom4jProxy.getParent(Dom4jProxy.java:177) at org.dom4j.tree.AbstractElement.addNode(AbstractElement.java:2130) at org.dom4j.tree.AbstractElement.add(AbstractElement.java:1412) at Main.main(Main.java:27) Fetching data with default EntityMode (now commented out in class Main) works fine. (Tried also with H3 from CVS. Posted to forum, but no response in a week, so suppose to be a bug.)

    Hibernate JIRA | 1 decade ago | Martin Caslavsky
    java.lang.ClassCastException: org.dom4j.tree.DefaultElement
  3. 0

    putting data from a LinkedBlockingQueue<> to an array not of type object

    Stack Overflow | 4 years ago | JohnM
    java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LdataStuff;
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    ClassCastException for casting Object[] to Trie.Node but not E[]

    Stack Overflow | 5 years ago | indil
    java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LTrie$Node; at Trie$Node.&lt;init&gt;(Trie.java:6) at Trie$Node.&lt;init&gt;(Trie.java:3) at Trie.&lt;init&gt;(Trie.java:10)

    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

      org.dom4j.tree.DefaultElement

      at org.hibernate.type.ComponentType.toLoggableString()
    2. Hibernate
      EntityKey.toString
      1. org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:279)
      2. org.hibernate.pretty.MessageHelper.infoString(MessageHelper.java:68)
      3. org.hibernate.engine.EntityKey.toString(EntityKey.java:77)
      3 frames
    3. Java RT
      StringBuffer.append
      1. java.lang.String.valueOf(String.java:2577)
      2. java.lang.StringBuffer.append(StringBuffer.java:220)
      2 frames
    4. Hibernate
      StringHelper.toString
      1. org.hibernate.util.StringHelper.toString(StringHelper.java:168)
      1 frame
    5. Hibernate
      AbstractCollectionPersister.initialize
      1. org.hibernate.loader.Loader.getRow(Loader.java:762)
      2. org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:295)
      3. org.hibernate.loader.Loader.doQuery(Loader.java:389)
      4. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208)
      5. org.hibernate.loader.Loader.loadCollection(Loader.java:1367)
      6. org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:107)
      7. org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
      7 frames
    6. Hibernate
      SessionImpl.initializeCollection
      1. org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
      2. org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1356)
      2 frames
    7. Hibernate
      BasicEntityPersister.load
      1. org.hibernate.type.CollectionType.getCollection(CollectionType.java:470)
      2. org.hibernate.type.CollectionType.resolveKey(CollectionType.java:328)
      3. org.hibernate.type.CollectionType.resolve(CollectionType.java:322)
      4. org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
      5. org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:494)
      6. org.hibernate.loader.Loader.doQuery(Loader.java:413)
      7. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208)
      8. org.hibernate.loader.Loader.loadEntity(Loader.java:1278)
      9. org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
      10. org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
      11. org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2491)
      11 frames
    8. Hibernate
      SessionImpl.immediateLoad
      1. org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:386)
      2. org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:367)
      3. org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
      4. org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
      5. org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:119)
      6. org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:593)
      6 frames
    9. Hibernate
      Dom4jProxy.getParent
      1. org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
      2. org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
      3. org.hibernate.proxy.Dom4jLazyInitializer.getElement(Dom4jLazyInitializer.java:21)
      4. org.hibernate.proxy.Dom4jProxy.target(Dom4jProxy.java:561)
      5. org.hibernate.proxy.Dom4jProxy.getParent(Dom4jProxy.java:177)
      5 frames
    10. dom4j
      AbstractElement.add
      1. org.dom4j.tree.AbstractElement.addNode(AbstractElement.java:2130)
      2. org.dom4j.tree.AbstractElement.add(AbstractElement.java:1412)
      2 frames
    11. Unknown
      Main.main
      1. Main.main(Main.java:27)
      1 frame