-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: XML export Fails for simply many to many example
PostPosted: Thu Sep 01, 2005 10:29 am 
Newbie

Joined: Thu Sep 01, 2005 10:08 am
Posts: 1
java.lang.ClassCastException: org.dom4j.tree.DefaultElement is thrown when converting a list to XML using the following simple code:
Code:
  <class name="com.rxp.hib.KeySet"
         table="keysets">
    <id name="id"
        type="integer"
        column="id"
        unsaved-value="-1">
      <generator class="identity"/>
    </id>
    <property name="name"
              column="NAME"
              not-null="true"
              unique="true"
              />
    <set name="keys"
         lazy="false"
         table="keyset_word">
      <key column="set_id"/>
      <many-to-many class="com.rxp.hib.Keyword"
                    column="key_id"
                    embed-xml="true"
       />
    </set>
  </class>

Code:
  <class name="com.rxp.hib.Keyword"
         table="keywords">       
    <id name="id"
        type="integer"
        column="id"
        unsaved-value="-1">
      <generator class="identity"/>
    </id>       
    <property name="name"
              column="NAME"
              not-null="true"
              unique="true"
              />
  </class>




Code:

public class KeySet
{
    protected static final int unset_value = -1;

    protected int    id;
    protected String name;
    protected Set    keys;

    /**
     * Default constructor
     */
    protected KeySet()
    {
        id   = unset_value;
        name = null;
        keys = null;
    }

    /**
     */
    public KeySet( String newName )
    {
        id   = unset_value;
        name = newName;
        keys = null;
    }

    /**
     * Get the Id value.
     * @return the Id value.
     */
    public int getId() {
        return id;
    }

    /**
     * Set the Id value.
     * @param newId The new Id value.
     */
    protected void setId(int newId) {
        this.id = newId;
    }

    /**
     * Get the Name value.
     * @return the Name value.
     */
    public String getName() {
        return name;
    }

    /**
     * Set the Name value.
     * @param newName The new Name value.
     */
    public void setName(String newName) {
        this.name = newName;
    }

    /**
     * Get the Keys value.
     * @return the Keys value.
     */
    public Set getKeys() {
        return keys;
    }

    /**
     * Set the Keys value.
     * @param newKeys The new Keys value.
     */
    public void setKeys(Set newKeys) {
        this.keys = newKeys;
    }

}



Code:
public class Keyword {

    protected static final int unset_value = -1;

    protected int    id;
    protected String name;

    /**
     * Default constructor
     */
    protected Keyword() {
        id          = unset_value;
        name        = null;
    }

    /**
     */
    public Keyword(String newName) {
        id          = unset_value;
        name        = newName;
    }

    /**
     * Get the Id value.
     * @return the Id value.
     */
    public int getId() {
        return id;
    }

    /**
     * Set the Id value.
     * @param newId The new Id value.
     */
    protected void setId(int newId) {
        this.id = newId;
    }

    /**
     * Get the Name value.
     * @return the Name value.
     */
    public String getName() {
        return name;
    }

    /**
     * Set the Name value.
     * @param newName The new Name value.
     */
    protected void setName(String newName) {
        this.name = newName;
    }

}


Code:
:
Session dom4JSession = session.getSession(EntityMode.DOM4J);
List result = dom4JSession.createQuery( "from KeySet as ks where ks.name='colors'" ).list();
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement(rootNode); 
    for (int i = 0; i < result.size(); i++) {
        Element e = (Element)result.get(i);
       root.add(e);
    }           
:


If this isn't possible then I think I've wasted the last couple of days learning Hibernate!

Cheers
Keith [/i]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.