-->
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.  [ 7 posts ] 
Author Message
 Post subject: Can I do a one-to-one to itself?
PostPosted: Sun Jan 16, 2005 2:41 pm 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
Code:
<hibernate-mapping>
    <class name="org.appfuse.model.Category" table="CATEGORY">
        <id name="id" type="long" column="CATEGORY_ID">
            <generator class="increment"/>
        </id>
      <property name="name" type="string" column="CATEGORY_NAME"/>
      <one-to-one name="parentId" column="CATEGORY_PARENTID" class="org.appfuse.model.Category"/>
    </class>
</hibernate-mapping>


I think it's pretty obvious what I'm trying to do here. Unfortunately, this spits out some errors, so I'm wondering if this is even possible? I just thought I'd save a lookup if I could store the whole parent "object" instead of just an id I'd have to do a lookup on.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 3:45 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
many to one is better in your case

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 7:40 pm 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
I'm just thinking out loud, but I'm wondering how I would keep track of the hierarchy of the parents if I make it a many-to-one?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:02 am 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
Anybody see anything wrong with this mapping?

Code:
<hibernate-mapping>
    <class name="org.appfuse.model.Category" table="CATEGORY">
        <id name="id" type="long" column="CATEGORY_ID">
            <generator class="increment"/>
        </id>
      <property name="name" type="string" column="CATEGORY_NAME"/>
      <set name="parents" table="CATEGORY_PARENTS">             
         <key column="CATEGORY_ID"/>             
         <many-to-one class="org.appfuse.mode.Category" column="PARENT_ID"/>
      </set>
    </class>
</hibernate-mapping>


I'm getting this error:
Code:
ERROR - XMLHelper$ErrorLogger.error(48) | Error parsing XML: XML InputStream(14) Attribute "name" is required and must be specified for element type "many-to-one".
ERROR - XMLHelper$ErrorLogger.error(48) | Error parsing XML: XML InputStream(15) The content of element type "set" must match "(meta*,(cache|jcs-cache)?,key,(element|one-to-many|many-to-many|composite-element|many-to-any))".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
<many-to-one> does not appear inside collection mappings. Do you mean <one-to-many>?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:13 am 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
If I did a one-to-many inside that mapping, would it represent one parent to many categories or vice-versa? I've been working with this associations all night and my brain is fried.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:29 am 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
I'm getting an odd error now:
Code:
ERROR - XMLHelper$ErrorLogger.error(48) | Error parsing XML: XML InputStream(14) Attribute "column" must be declared for element type "one-to-many".
ERROR - ContextLoader.initWebApplicationContext(124) | Context initialization failed


after changing the mapping to a one-to-many relationship
Code:
<hibernate-mapping>
    <class name="org.appfuse.model.Category" table="CATEGORY">
        <id name="id" type="long" column="CATEGORY_ID">
            <generator class="increment"/>
        </id>
      <property name="name" type="string" column="CATEGORY_NAME" not-null="true"/>
      <set name="parents" table="CATEGORY_PARENTS">             
         <key column="CATEGORY_ID"/>             
         <one-to-many class="org.appfuse.mode.Category" column="PARENT_ID"/>
      </set>
    </class>
</hibernate-mapping>


Any ideas?


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