-->
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.  [ 2 posts ] 
Author Message
 Post subject: ElementWrapper has scoping bugs, breaks adding Elements
PostPosted: Tue Mar 28, 2006 2:34 pm 
Newbie

Joined: Thu Mar 16, 2006 4:48 pm
Posts: 5
Hibernate version:
3.1.3 (current SVN Head)

Problem:

Hi all,

I'm using DOM4J entity mode, updating the DOM4J Element's, and then passing them back to update the database.

Everything works fine until you add a new Elements to the result (i.e. which was provided by Hibernate) because the code in ElementWrapper has a scoping bug (in six places).

Code:
public class ElementWrapper implements Element, Serializable {

  private Element element;
  private Element parent;

  // ...snip...

  public void add(Element element) {
    // BUG: Should be this.element.add(..)
    element.add( element );
  }

  // ...snip...
}


The net result is that that your new Element is set to be a parent of itself rather than a child of the Hibernate-generated element.

The same bug happens in 6 different places, each time because there is a parameter called element. The six methods are:
    getPath
    getUniquePath
    asXPathResult
    appendAttributes
    add(Element element)
    remove(Element element)

I have an updated ElementWrapper.java if it's of any use...?

Regards,
John


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 1:29 pm 
Newbie

Joined: Tue Mar 25, 2008 12:39 pm
Posts: 2
I am also using dom4j dynamic model. I have a problem with removing of an entity from a list of values.

Suppose, I have the following mapping:
Code:
<hibernate-mapping>
   <class entity-name="Parent" node="Parent">
      <id name="id_" type="long">
         <generator class="native"/>
      </id>
      <list name="children">
         <key column="parentid_"/>
         <list-index column="LIST_INDEX"/>
         <one-to-many class="Child"/>
      </list>
   </class>
   <class entity-name="Child" node="Child">
      <id name="id_" type="long">
         <generator class="native"/>
      </id>
      <property name="name" type="string"/>
   </class>
</hibernate-mapping>

Also, suppose, I have an instance of "Parent" with more than one "Child" in "children" list.

When I execute the following code:
Code:
      Element parent = ....;
      Element children = parent.element("children");
      List childrenList = children.elements("Child");
      for (int i = 0, k = childrenList.size(); i < k; i++) {
         Element child = (Element)childrenList.get(i);
         [b]children.remove(child);[/b]
         session.delete(valueElement_);
      }
      session.update(parent);

hibernate updates the database, but child elements still contains in children element. In other words, when children.remove(child); line is executed, it does not work because org.hibernate.tuple.ElementWrapper wrongly implements equals(Object) method (children is an instance of org.dom4j.tree.DefaultElement and child is an instance of org.hibernate.tuple.ElementWrapper).

Here is more simplified example of the bug:
Code:
      DefaultElement child1 = new DefaultElement("child", null);
      child1.setText("child 1");
      DefaultElement child2 = new DefaultElement("child", null);
      child2.setText("child 2");
      ElementWrapper child1Wrapper = new ElementWrapper(child1);
      ElementWrapper child2Wrapper = new ElementWrapper(child2);
      DefaultElement parent = new DefaultElement("parent");
      parent.add(child1Wrapper);
      parent.add(child2Wrapper);
      parent.remove(child1Wrapper);
      parent.remove(child2Wrapper);
      Iterator childs = parent.elementIterator();
      while(childs.hasNext()) {
         Element ch = (Element)childs.next();
         System.out.println(ch.getText());
      }


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

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.