-->
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 many-to-one breaks node name (dom4j entity mode)
PostPosted: Sat Feb 24, 2007 1:41 am 
Newbie

Joined: Sun Jan 21, 2007 6:48 am
Posts: 6
Location: El Cerrito, CA
The same class can be both parent and child in this setup. There should be four top-level Company nodes, and this works fine when the child many-to-one has embed-xml set to false.

But when embed-xml is set to true, one of the top-level node names changes from Company to the value it has when it is a child under another node!

Hibernate version:
3.2.2
dom4j version 1.6.1

Mapping documents:
Code:
<hibernate-mapping>
    <class name="hibernatexml.Company" table="Company">
        <id name="company" node="@company">
            <generator class="native"/>
        </id>
        <property name="companyName"/>

            <many-to-one name="clientOf"
              class="hibernatexml.Company"
              embed-xml="true"
              column="ClientOf"/>

            <set name="clients" inverse="true"
               table="Company">
               <key column="clientOf"/>
               <one-to-many class="hibernatexml.Company"
                  embed-xml="false"/>
            </set>
    </class>
</hibernate-mapping>


When embed-xml is set to false for clientOf everything works as expected, and I get this xml output:

Code:
<Companies>
  <Company company="1">
    <companyName>Hooja</companyName>
    <clients/>
  </Company>
  <Company company="23">   <!-- CORRECT TAG NAME -->
    <companyName>Agency A</companyName>
    <clients>
      <Company>41</Company>
      <Company>42</Company>
    </clients>
  </Company>
  <Company company="41">
    <companyName>Client A1</companyName>
    <clientOf>23</clientOf>
    <clients/>
  </Company>
  <Company company="42">
    <companyName>Client A2</companyName>
    <clientOf>23</clientOf>
    <clients/>
  </Company>
</Companies>


However, when embed-xml is set to true the Company tag for company 23 turns into a clientOf tag (see my comment in the xml below)! It appears that when the node name for company 23 is set to clientOf when it is a child of companies 41 and 42 it "sticks" even when it is being displayed at the top level, when it should just say Company!

Code:
<Companies>
  <Company company="1">
    <companyName>Hooja</companyName>
    <clients/>
  </Company>
  <clientOf company="23">  <!-- PROBLEM WITH THIS TAG NAME -->
    <companyName>Agency A</companyName>
    <clients>
      <Company>41</Company>
      <Company>42</Company>
    </clients>
  </clientOf>
  <Company company="41">
    <companyName>Client A1</companyName>
    <clientOf company="23">        <!-- OKAY HERE -->
      <companyName>Agency A</companyName>
      <clients>
        <Company>41</Company>
        <Company>42</Company>
      </clients>
    </clientOf>
    <clients/>
  </Company>
  <Company company="42">
    <companyName>Client A2</companyName>
    <clientOf company="23">
      <companyName>Agency A</companyName>
      <clients>
        <Company>41</Company>
        <Company>42</Company>
      </clients>
    </clientOf>
    <clients/>
  </Company>
</Companies>



I have a test case ready to upload if that would help anybody analyze this issue.

Thanks in advance for any insight!

Code between sessionFactory.openSession() and session.close():
Code:
    static public void main(String[] args) {
        CompanyDAO Me = new CompanyDAO();
        Me.testDom4j();
    }

    private void testDom4j() {
        /* dom4j xml doc */
        Document doc = getAllAsXml();

        /* Output */
        try {
          OutputFormat format = OutputFormat.createPrettyPrint();
          XMLWriter writer = new XMLWriter( System.out, format);
          writer.write( doc );
        } catch (IOException ex) {
          throw new RuntimeException(ex);
        }
    }

    private Document getAllAsXml() {

        /* dom4j xml doc to return */
        Document doc = DocumentHelper.createDocument();

        Session dom4jSession = getSession().getSession(EntityMode.DOM4J);

        Order order = Order.asc("company");
        List<Company> types = findAndOrderByCriteria(order);

        Element rootElmnt = doc.addElement("Companies");
        if (types != null) for (Company type : types) {
            Element typeElmnt
                    = (Element)dom4jSession.load(
                        Company.class,
                        type.getCompany());
             rootElmnt.add(typeElmnt.detach());
         } // next type
         return doc;
    }


Name and version of the database you are using:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production


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.