-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping 1-2-1 with NHibernate 1.2.0- Alpha
PostPosted: Tue Jul 11, 2006 9:53 am 
Newbie

Joined: Sat Jun 17, 2006 12:43 pm
Posts: 5
Hibernate version: 1.2.0 - alpha


Hi all,

I am trying to map a self join type relation (1-2-1) mapping as described below, but it doesn't appear to work.

Here's a piece of snippet.

I have a table

Task
(Task_Id number,
Name varchar,
Refers_to number,
Depends_on Number);

the relation is like this

Task__Name ______Refers_To__Depepends_on
1.........Make Coffee................null...............null
2.........Drink Coffee................null............... 1
3.........Make milky coffee........ 1................. 1
(... and so on)

This is just to illustrate that Refers_to and Depends_on are the "Task ID" itself

Now, in the class, i have the following definition

class Task
{
private int taskId;
private string name;
private Task refersTo;
private Task dependsOn;
//corresponding getters and setters here....
}


in the mapping file, i have the following for the two properties:

<one-to-one name="RefersTo" class="mynamespace.Task, myAssembly" />

note: I tried putting in foreign-key as "Task_ID", tried changing it to "REFERS_TO" and so on...

There are no errors in loading and running the app, but when I try saving, the Task gets saved as normal, but if any Task is set to REFERS_TO or DEPENDS_ON is not saved. They are saved as NULL (always)

When loading, the two properties (Task.RefersTo and Task.DependsOn) point to the class itself.

i.e. If I load ID=1
the I get

Task t = LoadWithID(1);
the corresponding values are...

t = Make Coffee
t.RefersTo = Make Coffee
t.DependsOn = Make Coffee.

I don't know why these are being set.

Pleas let me know if I have made any mistake or if this is any known issues.

Many thanks
Sath


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 2:27 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
That's because what you have is not one-to-one. What you have is a many-to-one association and you should map it using <many-to-one name="RefersTo" column="Refers_to" />.


Top
 Profile  
 
 Post subject: This worked
PostPosted: Fri Jul 14, 2006 11:36 am 
Newbie

Joined: Sat Jun 17, 2006 12:43 pm
Posts: 5
many thanks

This worked. It was my mistake indeed! Being a newbie sucks!!! ;)

Once again, I appreciate all your help.


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