-->
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: List contains null values up to count of all rows in db tbl
PostPosted: Mon Nov 13, 2006 4:16 pm 
Newbie

Joined: Mon Nov 13, 2006 3:55 pm
Posts: 2
Hi,

I have a domain object called InviteeReportFilter. In that class, there is a list of filter strings called FilterSearchValues. For some reason my mapping is wrong but I don't know what part is wrong (newbie). The list is returning 44 null value strings in that list and then 1 string that has the acutal value which matches the sql query that NHibernate generates. The SQL query returns on 1 row, and I am assuming the other 44 nulls are generated from the 44 other rows in the ReportFilter table. I have the mapping set for the list do to a select and have outer joins turned off. What would make NHibernate insert 44 rull strings in my list when the SQL script that is run by NHibernate only returns 1 row??

Mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="RemoteNet.EventRegistration.Domain" assembly="RemoteNet.EventRegistration.Domain">
<class name="InviteeReportFilter" table="ReportFilter" >

<!--IDENTITY-->
<id name="Id" column="ReportFilterId" unsaved-value="0" access="field.camelcase-underscore">
<generator class="identity" />
</id>

<!--VERSION-->
<version name="Version" column="Version" access="field.camelcase-underscore"></version>

<!--PROPERTIES-->
<property name="Field" column="FieldId" length="50" not-null="true" access="field.camelcase-underscore" />

<!--COLLECTIONS -->
<list name="FilterSearchValues" access="field.camelcase-underscore" table="ReportFilterSearchValue" lazy="true" fetch="select" outer-join="false">
<key column="ReportFilterId" />
<index column="ReportFilterSearchValueId" type="Int32"/>
<element column="SearchValue" not-null="true" unique="false" type="String" />
</list>

<!--ASSOSCIATIONS-->
<many-to-one name="ReportSettings" column="ReportId" class="InviteeReportSettings" access="nosetter.camelcase-underscore" outer-join="false" not-null="true" fetch="select" cascade="none" update="false" />
</class>
</hibernate-mapping>

Resulting SQL:

exec sp_executesql N'SELECT reportfilt0_.ReportId as ReportId__1_, reportfilt0_.ReportFilterId as
ReportFi1_1_, inviteerep1_.ReportFilterId as ReportFi1_2_0_, inviteerep1_.Version as Version2_0_,
inviteerep1_.FieldId as FieldId2_0_, inviteerep1_.ReportId as ReportId2_0_ FROM
EventRegistration.dbo.ReportFilter reportfilt0_ left outer join EventRegistration.dbo.ReportFilter
inviteerep1_ on reportfilt0_.ReportFilterId=inviteerep1_.ReportFilterId WHERE
reportfilt0_.ReportId=@p0',N'@p0 int',@p0=14

Create Script for Table:

USE [EventRegistration]
GO
/****** Object: Table [dbo].[ReportFilterSearchValue] Script Date: 11/13/2006 12:06:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ReportFilterSearchValue](
[ReportFilterSearchValueId] [int] IDENTITY(1,1) NOT NULL,
[ReportFilterId] [int] NOT NULL,
[SearchValue] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_ReportFilterSearchValue] PRIMARY KEY CLUSTERED
(
[ReportFilterSearchValueId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
USE [EventRegistration]
GO
ALTER TABLE [dbo].[ReportFilterSearchValue] WITH CHECK ADD CONSTRAINT [FK_ReportFilterSearchValue_ReportFilter] FOREIGN KEY([ReportFilterId])
REFERENCES [dbo].[ReportFilter] ([ReportFilterId])
ON DELETE CASCADE

Thanks for helping me out!
Sean


Top
 Profile  
 
 Post subject: Re: List contains null values up to count of all rows in db
PostPosted: Tue Nov 14, 2006 4:44 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
scarlin wrote:
<index column="ReportFilterSearchValueId" type="Int32"/>


I guess that that the Id of filter is 44? Anyway, in case of list, NHibernate ensures that the value ends up in list at position stored in index column, and inserts nulls if there are no items for some positions.

Maybe <bag> mapping is more appropriate for You?

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 10:36 am 
Newbie

Joined: Mon Nov 13, 2006 3:55 pm
Posts: 2
Hi Gert,

Thanks for the quick reply! I changed the collection from a list to a bag and now all the null values are gone. I didn't realize that the list collection would have null values so that each item would be in the proper index of the collection. I guess that makes sense as to why the mappings file has an <index> element for the list. I didn't quite glean this from pages 213-214 of Hibernate in Action. Thanks for helping me out!!! Now I understand this awesome mapper even more (still have a lot to learn....).

Regards,
Sean


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.