Mapping columns from other tables directly into a property

3 views
Skip to first unread message

Saijado

unread,
Jul 28, 2009, 4:43:53 AM7/28/09
to nhusers
Hallo,

when I saw the new <join/> feature in the realeasenotes of NH2.0 I
thought that I can map columns with a many-to-one assosiation from
other tables direct into a property in my class but this is for one-to-
one only. This would be very helpfull for somthing like a title of a
person. Now I need a Title-class to map this for one string property.

Is there any other way to map a property direct to another table?

Belvasis

unread,
Jul 28, 2009, 7:18:20 AM7/28/09
to nhu...@googlegroups.com
And what will you do if one want to add new titles or edit existing titles? I think then you'll need a Title class
otherwise you could use a simple title field in the person table.

2009/7/28 Saijado <sai...@googlemail.com>

Armin Landscheidt

unread,
Jul 28, 2009, 7:43:16 AM7/28/09
to nhu...@googlegroups.com
Yes but this are two different things. In my case I want just view a value which were written from a completly different part of the application. If i do this with many-to-one my class looks like

class Person{
      public string Name{get;set;}
      public string Title{ get{ return title.text} }
      private Title title;
}

otherwise it would look like

class Person{
      public string Name{get;set;}
      public string Title{ get; private set; }
}

I need this in cases where I have another view on the data. So the objectmodel can be different from other parts in the Application. The other parts need to know about the Title class in this point you are right.

Belvasis

unread,
Jul 28, 2009, 8:34:00 AM7/28/09
to nhu...@googlegroups.com
Ah ok...maybe this could help http://blog.tieredsolutions.com/?p=527

2009/7/28 Armin Landscheidt <sai...@googlemail.com>

Armin Landscheidt

unread,
Jul 28, 2009, 11:23:54 AM7/28/09
to nhu...@googlegroups.com
Ok thanks for your help. But the Problem on this solution is, that NHibernate would fire the select per object.

Belvasis

unread,
Jul 28, 2009, 12:47:03 PM7/28/09
to nhu...@googlegroups.com
Yes thats true, there is another using a view and entity name. I read it somewhere at NHforge. But i think it is easier to use an separate Title entity.

Raul Carlomagno

unread,
Jul 28, 2009, 8:54:15 PM7/28/09
to nhusers

Armin Landscheidt

unread,
Jul 29, 2009, 3:24:40 AM7/29/09
to nhu...@googlegroups.com
Yes formular would work, but I think it will be to slow, because it would fire one statement for each loaded object.

2009/7/29 Raul Carlomagno <rcarl...@gmail.com>

Armin Landscheidt

unread,
Jul 30, 2009, 6:06:50 AM7/30/09
to nhu...@googlegroups.com
Now I have tried to use the propertyref but NHibernate is still using the RecId of the Parentclass. Should I make an entry on the Jira database?

2009/7/29 Armin Landscheidt <sai...@googlemail.com>

similitude2009

unread,
Jul 30, 2009, 1:04:10 PM7/30/09
to nhusers
I am tring to do the same thing using foreign-key and property-ref but
none seems to work.

Employe
{int id;
string name;
int IdEmployeType;
}

EmployeType
{int Id;
string EmployeTypeName;
}

The data are in 2 tables with a foreign key between
Employe.IdEmployeType and EmployeType.Id

I want to do this
Employe
{int id;
string name;
string EmployeTypeName;
}

Then in the mapping of Employe i try

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="false">
<class name="Employe" table="Employe" batch-size="200">
<id name="Id" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" column="Name" type="String" />
<join table="EmployeType" fetch="select" optional="true">
<key column="Id" foreign-key="IdEmployeType"/>
<property name="EmployeTypeName" column="EmployeTypeName"
type="String"/>
</join>
</class>
</hibernate-mapping>

or

<join table="EmployeType" fetch="select" optional="true">
<key column="Id" property-ref ="IdEmployeType"/>
<property name="EmployeTypeName" column="EmployeTypeName"
type="String"/>
</join>

None works.

Saijado

unread,
Jul 30, 2009, 2:46:11 PM7/30/09
to nhusers
Property-ref will be ignored. Maybe it's not implemented for this
case. Here i think this is the case we need http://nhjira.koah.net/browse/NH-1220
. I hope it will be implmented soon.
Reply all
Reply to author
Forward
0 new messages