-->
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.  [ 6 posts ] 
Author Message
 Post subject: Recursive relationship ... duplicate import error
PostPosted: Tue Mar 30, 2004 6:31 am 
Beginner
Beginner

Joined: Tue Mar 30, 2004 5:54 am
Posts: 22
Location: Bangalore
New to Hibernate ... using hibernate 2.1.2 with Struts.

I have Organisation with recursive reloationship ... (one-to-many relationship) ... I have the following hbm file ...

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   <class name="mydomain.Organisation" table="ORGANIZATIONS">

        <id name="orgCode" type="string" length="20">
           <column name="org_code" sql-type="varchar(20)" not-null="true"/>
           <generator class="assigned"/>
        </id>

        <property name="name" column = "org_name"/>
        <property name="shortName" column ="short_name"/>
        <property name="sapCode" column="sap_code"/>
      <property name="divHead" column="div_head"/>
      <property name="phone" column="tel"/>
      <property name="mpaGroup" column="mpa_group" />
      <!--many-to-one name= "parentCode" column= "prnt_org_code"/ -->
      
      <set name="organisations" cascade="all" inverse="true">
         <key  column="org_code" foreign-key="prnt_org_code" />
         <one-to-many class="mydomain.Organisation" />
      </set>
   </class>

</hibernate-mapping>


When running I am getting and error duplicate import ... I found in the forum that there must be some error in the mapping file.

Will you please let me know is there any error in this mapping document?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 6:56 am 
Newbie

Joined: Mon Mar 22, 2004 5:23 am
Posts: 18
Location: Bangalore
Change the line

<key column="org_code" foreign-key="prnt_org_code" />

to

<key column="prnt_org_code" />

thanks
santosh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 7:02 pm 
Newbie

Joined: Tue Mar 23, 2004 12:21 pm
Posts: 11
Hello Misirfani,
Just wanted to know , if this solution worked for you. I have a same problem.
According to documentation 'Collections may not contain other collections'. As i can see from the code sniplet that Your master object and the asscoate object is same. If the Master object has a set , so will be the associate object.
But that may not work according the documentaion. However if this has worked for you , I will be very interested to know, how?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 12:58 am 
Beginner
Beginner

Joined: Tue Mar 30, 2004 5:54 am
Posts: 22
Location: Bangalore
Thanks Santosh ...

It did worked ... How ... it is very difficult for me to answer ... (since I am new to both Java as well as Hibernate) but I can see from the Debug window that the parent collection Organisation do have a set named organisations of type net.sf.hibernate.collection.Set

May be they are yet to update the Documentation.

Once again ... Thanks Santosh.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 1:28 am 
Newbie

Joined: Mon Mar 22, 2004 5:23 am
Posts: 18
Location: Bangalore
Hi msirfani,

It worked because within the following Set element

<set name="organisations" cascade="all" inverse="true">
<key column="prnt_org_code" />
<one-to-many class="mydomain.Organisation" />
</set>

, the key column denotes the foreign key. Yours is a case of self-referential integrity where the foreign key is in the same table.

The documentation , I believe,is sufficient as far as collections and parent-child relation ships are concerned.

Go thru the following link for more info.
http://www.xylax.net/hibernate/

thanks
santosh


Top
 Profile  
 
 Post subject: Got IT!
PostPosted: Sat Apr 03, 2004 6:15 am 
Beginner
Beginner

Joined: Tue Mar 30, 2004 5:54 am
Posts: 22
Location: Bangalore
Thanks santosh I got it ... now I know what is the mistake!

_________________
Thanks
Irfani


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.