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: Relations
PostPosted: Mon Sep 08, 2008 6:55 am 
Newbie

Joined: Thu Mar 15, 2007 8:03 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:1.2



I all,

I have this situation:

Table 1 with this columns:

id
parentId
name
etc...


parentId have id values, so how can i map this?

parentId is the FK for the Table1! :)


greetings


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 11:53 am 
Newbie

Joined: Tue Sep 09, 2008 11:06 am
Posts: 6
Location: Illinois, USA
It looks like you're trying to build a tree; if that's the case, this mapping should work fine, otherwise you could just replace the "Children" inverse bag with a "Child" property. You may need to modify the id and generator elements to suit your needs as well.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="YourApp" namespace="YourApp.Namespace">
   <class name="Table1" table="Table1">
    <id name="Id" column="id" type="Int64">
      <generator class="identity"/>
    </id>
    <property name="Name" column="name"/>
    <many-to-one class="Table1" name="Parent" column="parentId" cascade="save-update"/>
    <bag name="Children" cascade="save-update" inverse="true">
      <key column="parentId"/>
      <one-to-many class="Table1"/>
    </bag>
   </class>
</hibernate-mapping>


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.