-->
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.  [ 5 posts ] 
Author Message
 Post subject: newbe problems ... easy one here
PostPosted: Sun Jul 05, 2009 4:07 pm 
Newbie

Joined: Sat Jul 04, 2009 6:45 pm
Posts: 2
Hi all,

I'm new to nhibernate so this should be easy. I have a mapping file as below although I deleted some fields that aren't relevant to this question. The streamfields class contains a bag of fieldmappings. I want the join to be on field_no column but the sql that is sent is on the id field (<id name="StrFldId" column="`str_fld_id`") as seen below.

I see what the below sql is doing but it's not what I wanted. It's trying to query the field_mappings table based on the values found in the id column str_fld_id in the StreamFields class when I thought it was clear I wanted the field_no to be used on both ends. I say I thought it was clear because the mapping for the field_mapping class has the below attribute and they both have the same named field.

Can someone help me out? Thanks.

Below is in my FieldMappings mapping file
<many-to-one name="FieldNo" cascade="none" column="`Field_No`" not-null="true" />

Sql sent
-----------------------
NHibernate: SELECT fkfieldmap0_.[field_no] as field5_1_, fkfieldmap0_.[Mapping_Id] as Mapping1_1_, fkfieldmap0_.[Mapping_Id] as Mapping1_3_0_, fkfieldmap0_.[Std_fld_Id] as Std2_3_0_, fkfieldmap0_.[Field_Position] as Field3_3_0_, fkfieldmap0_.[Field_No] as Field4_3_0_ FROM [Field_Mappings] fkfieldmap0_ WHERE fkfieldmap0_.[field_no]=@p0; @p0 = '20'
----------------
StreamFields mapping
----------------
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DataTransfer.StreamFields,DataTransfer" table="`stream_fields`" lazy="true">
<id name="StrFldId" column="`str_fld_id`" type="int">
<generator class="native" />
</id>
<property type="int" not-null="true" name="FieldNo" column="`field_no`" />
<many-to-one name="StreamId" cascade="none" column="`stream_Id`" />
<bag name="FkFieldMappingsStreamFields" inverse="true" lazy="false" cascade="all">
<key column="`field_no`" />
<one-to-many class="DataTransfer.FieldMappings,DataTransfer"/>
</bag>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: newbe problems ... easy one here. More details
PostPosted: Mon Jul 06, 2009 1:32 pm 
Newbie

Joined: Sat Jul 04, 2009 6:45 pm
Posts: 2
To make this problem more clear. the name of the field isn't mentioned in the query but it used the values found in the field called 'StrFldId' to try and look up the field mappings when it should be using the values from the field_no field.

There is no value 20 in the field_no field but that value is found in the strfldid field.

So, the below query is using the values in StrFldId when I thought it would use field_no values.

SELECT fkfieldmap0_.[field_no] as field5_1_, fkfieldmap0_.[Mapping_Id] as Mapping1_1_, fkfieldmap0_.[Mapping_Id] as Mapping1_3_0_, fkfieldmap0_.[Std_fld_Id] as Std2_3_0_, fkfieldmap0_.[Field_Position] as Field3_3_0_, fkfieldmap0_.[Field_No] as Field4_3_0_ FROM [Field_Mappings] fkfieldmap0_ WHERE fkfieldmap0_.[field_no]=@p0; @p0 = '20' –


Top
 Profile  
 
 Post subject: Re: newbe problems ... easy one here
PostPosted: Mon Jul 27, 2009 10:18 am 
Newbie

Joined: Mon Jul 27, 2009 10:09 am
Posts: 4
spacecowboy, check out http://www.rmfusion.com. There are some useful code examples on NHibernate.NET under the Open Source section.


Top
 Profile  
 
 Post subject: Re: newbe problems ... easy one here
PostPosted: Thu Jul 30, 2009 2:02 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik, you can't do that. A collection mapping always uses the id of the parent for querying the child records. Is there a special reason why you want/need to use a separate column for that ? It seems to be a redundant information.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: newbe problems ... easy one here
PostPosted: Wed Aug 05, 2009 12:34 pm 
Newbie

Joined: Wed Aug 05, 2009 12:23 pm
Posts: 2
Major newbie here too. If I'm understanding you right then try this

in your bag do

<key column="`field_no`" property-ref="`field_no`"/>


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