-->
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: one-many mapping Found shared references to collection issue
PostPosted: Fri Nov 06, 2009 4:15 pm 
Newbie

Joined: Mon Oct 26, 2009 9:28 am
Posts: 1
Hi,

I am trying to create hibernate mapping file for saving XML -to database using dom4j.we have one main table for all attribute of parentelement/childelements with only one occurence and seperate tables for child elements with multiple occurences. So i am using one-to-many within collection mappings but its giving me shared references error while persisiting to the database.

I am new to hibernate, any suggestion will be very helpful, i am able to iterate thru using code and save them successfuly but that is taking long time so instead i want to use hibernate collection/associations mapping feature and save it directly

my xml looks like this
<rootelement>
<parentelement>
<childelement1>
<childelement2>
<childelement2>
<childelement3>
<childelement3>
</parentelement>
</rootelement>

below is main hbm/child mapping .

Code:
<hibernate-mapping>

  <class table="maintable" entity-name="parentelement" node="parentelement">
        <id name="id" type="long" column="lnid" >
          <generator class="increment" />
        </id>       
       <!--  parent element Mapping -->
       <property
            .
           .
        <component name="childelement1" node="childelement1" >
       
      </component>
     
      <set name="childelements2" node="." cascade="all"  embed-xml="false">
            <key column="parentid" />
            <one-to-many entity-name="childelement2"  node="childelement2" />
           
        </set>
        <set name="childelements3" node="." cascade="all"  >
            <key column="parentid" />
            <one-to-many entity-name="childelement3"  node="childelement3"  />
        </set>
    </class>

<class entity-name="childelement2"  table="childtable"  node="childelement2">
        <id name="id" type="long" column="childid2"  >
          <generator class="increment"/>
        </id>
             <property .......
                     
  </class>
</hibernate-mapping>


I am using the below code to persist, since we have large xml i am using batch mode to insert into db
Code:
reader.addHandler( "/rootelement/parentelement",
          new ElementHandler() {
         
              public void onStart(ElementPath path)
              {
                         count++;
                        if ((count % 1000 )== 0 )  System.out.println(count);
              }

   public void onEnd(ElementPath path) {
                  // process a element
                 
                 try {
                     Element row = path.getCurrent();
                         Session dom4jSession = session.getSession(EntityMode.DOM4J);                        tx = session.beginTransaction();
               dom4jSession.saveOrUpdate("parentelement", row);                                      row.detach();
               //saving in batch mode
                        if ((count % 10) ==0)
                        {
                           if (session != null)
                           {
                              dom4jSession.flush();
                              dom4jSession.clear();
                         tx.commit();                                                  }
            }
               catch(HibernateException he)
                    {
                    
                    he.printStackTrace();
                  if (session != null)
                    {
                        tx.rollback();
                       session.clear();
                       session.close();
                       
               }


Top
 Profile  
 
 Post subject: Re: one-many mapping Found shared references to collection issue
PostPosted: Wed Jun 09, 2010 10:34 am 
Newbie

Joined: Tue Jun 08, 2010 3:08 pm
Posts: 5
Location: Rio de Janeiro, Brasil
Hi, I am having the same problem. The thing is that the <set> or <bag> tags does not accept the "node" property set to the actual node. At least for me, the mapping only works if the value is "."

Did you find a solution? Thanks for any help. I have a similar post here: https://forum.hibernate.org/viewtopic.php?f=1&t=1005085


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.