-->
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 to one question
PostPosted: Fri Feb 18, 2005 5:19 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
Hello I am strugglinh with my Folder object. A folder has a list of child and may have ONE father. So a one to many to itself and a one-to-one to itself.

I cannot make my one-to-one work probably. The one to one relation is done in my database by a field called FK_Father_Folder_ID. Right now the father of an Folder object is the object itself.


thanks

Hibernate version:2.1

Mapping documents:

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 package="data">

    <class name="Folder" table="folder">
        <id name="folderID" column="Folder_ID" type="java.lang.Integer"  unsaved-value="0" >
            <generator class="native"/>
        </id>

        <property name="folderName" column="Folder_Name" type="java.lang.String"  not-null="true" />
        <property name="folderCreatedDate" column="Folder_Created_Date" type="java.lang.Long"  not-null="true" />
      
      <one-to-one name="fatherFolder" class="Folder" cascade="all"  />
        <one-to-one name="project" class="Project" cascade="all" />
           
       <list name="childfolders" table="folder" cascade="all">
          <key column="FK_Father_Folder_ID"/>
          <index column="list_idx" />
          <one-to-many class="data.Folder"/>
       </list>


      <list name="pictures" table="picture" cascade="all">
          <key column="FK_Folder_ID"/>
          <index column="list_idx" />
          <one-to-many class="data.Picture"/>
       </list>
   
   
    </class>
   
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 11:47 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You have to use a many-to-one mapping instead a one-to-mapping. The child is on the many side of its father.

HTH
Ernst


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.