ArgumentException from EntityKey constructor when running a HQL query

Description

I have an object, Prospect, which I am searching for using a Criteria. I set a rather large number of fetch modes on this criter:

DirectCampaignSegment:Join
DirectCampaignSegment.DirectCampaign:Join
DirectCampaignSegment.DirectCampaign.Contract:Join
DirectCampaignSegment.DefaultProgram:Join
Member:Join
Member.Replaces:Join
Member.ACHAccounts:Join

In EntityKey.cs on line 35 I get the following error:

if( !identifierType.ReturnedClass.IsAssignableFrom( id.GetType() ) )
{
throw new ArgumentException( "identifier type mismatch", "id" );
}

At the point the code breaks, 'clazz' is MemberACHAccount. Yet the 'id' value is a valid DirectCampaignSegment id.

exec sp_executesql N'SELECT this_.Prospect_ID as Prospect1_0_7_, this_.Seg_ID as Seg2_0_7_, this_.MemberId as MemberId0_7_, this_.ParticipantId as Particip4_0_7_, this_.OriginalCoverageId as Original5_0_7_, this_.CoverageType as Coverage6_0_7_, this_.CoverageAmount as Coverage7_0_7_, this_.CorrespondenceId as Correspo8_0_7_, this_.InsuredId as InsuredId0_7_, this_.NewCoverageId as NewCove10_0_7_, directcamp2_.Id as Id34_0_, directcamp2_.DirectCampaignId as DirectCa2_34_0_, directcamp2_.DefaultForChannel as DefaultF3_34_0_, directcamp2_.DefaultProgramId as DefaultP4_34_0_, directcamp2_.CorrespondenceId as Correspo5_34_0_, directcamp2_.EffectiveDate as Effectiv6_34_0_, directcamp2_.Name as Name34_0_, directcamp3_.Id as Id31_1_, directcamp3_.ContractId as ContractId31_1_, contract4_.Id as Id29_2_, contract4_.EnrollmentUrl as Enrollme2_29_2_, contract4_.EffectiveDate as Effectiv3_29_2_, contract4_.ExpireDate as ExpireDate29_2_, contract4_.CancelDate as CancelDate29_2_, contract4_.ClientId as ClientId29_2_, contract4_.ProductId as ProductId29_2_, contract4_.ManagingBrokerId as Managing8_29_2_, program5_.Id as Id42_3_, program5_.Name as Name42_3_, program5_.ProgramProfileId as ProgramP3_42_3_, program5_.ContractId as ContractId42_3_, program5_.EffectiveDate as Effectiv5_42_3_, program5_.EndDate as EndDate42_3_, program5_.EnrollmentEndDate as Enrollme7_42_3_, program5_.DescriptionHtml as Descript8_42_3_, program5_.EnrollmentDocumentTemplateStackId as Enrollme9_42_3_, program5_.InformationDocumentTemplateStackId as Informa10_42_3_, program5_.ProcessEnrollments as Process11_42_3_, program5_1_.BasicCoverageAmount as BasicCov2_63_3_, case when program5_1_.Id is not null then 1 when program5_.Id is not null then 0 end as clazz_3_, member6_.Id as Id13_4_, member6_.IntId as IntId13_4_, member6_.ClientId as ClientId13_4_, member6_.FirstName as FirstName13_4_, member6_.MiddleName as MiddleName13_4_, member6_.LastName as LastName13_4_, member6_.Address1 as Address7_13_4_, member6_.Address2 as Address8_13_4_, member6_.City as City13_4_, member6_.StateOrProvince as StateOr10_13_4_, member6_.PostalCode as PostalCode13_4_, member6_.DateOfBirth as DateOfB12_13_4_, member6_.EMailAddress as EMailAd13_13_4_, member6_.CRC32 as CRC14_13_4_, achaccount7_.MemberId as MemberId_9, achaccount7_.Id as Id9_, achaccount7_.Id as Id53_5_, achaccount7_.MemberId as MemberId53_5_, achaccount7_.Type as Type53_5_, achaccount7_.Number as Number53_5_, achaccount7_.TransitRoutingNumber as TransitR5_53_5_, replaces8_.MemberId as MemberId_10, member9_.Id as Original2_10_, member9_.Id as Id13_6_, member9_.IntId as IntId13_6_, member9_.ClientId as ClientId13_6_, member9_.FirstName as FirstName13_6_, member9_.MiddleName as MiddleName13_6_, member9_.LastName as LastName13_6_, member9_.Address1 as Address7_13_6_, member9_.Address2 as Address8_13_6_, member9_.City as City13_6_, member9_.StateOrProvince as StateOr10_13_6_, member9_.PostalCode as PostalCode13_6_, member9_.DateOfBirth as DateOfB12_13_6_, member9_.EMailAddress as EMailAd13_13_6_, member9_.CRC32 as CRC14_13_6_ FROM Prospects this_ left outer join DirectCampaignSegment directcamp2_ on this_.Seg_ID=directcamp2_.Id left outer join DirectCampaign directcamp3_ on directcamp2_.DirectCampaignId=directcamp3_.Id left outer join Contract contract4_ on directcamp3_.ContractId=contract4_.Id left outer join Program program5_ on directcamp2_.DefaultProgramId=program5_.Id left outer join InsurancePlan program5_1_ on program5_.Id=program5_1_.Id left outer join Member member6_ on this_.MemberId=member6_.Id left outer join MemberAccount achaccount7_ on member6_.Id=achaccount7_.MemberId left outer join MemberReplacement replaces8_ on member6_.Id=replaces8_.MemberId left outer join Member member9_ on replaces8_.OriginalMemberId=member9_.Id WHERE this_.CorrespondenceId = @p0', N'@p0 int', @p0 = 1386139

Sorry for the length of that. Notice the second selected field: `this_.Seg_ID as Seg2_0_7_` This is the int which is trying to be used as the <id> However, it's not really the right field! The right field for MemberACHAccount would be `achaccount7_.Id as Id9_` Hmm. I notice that both Id*_ and FieldName_X_Y_ are selected for some things, yet I see no selection for DirectCampaignSegment.Id in that query. Where is it going?

The Seg_ID field is actually the FK for the DirectCampaignSegment relationship (many-to-many). It is somehow getting this confused with the MemberACHAccount Id.

Environment

None

Attachments

1

Activity

Show:
Former user
March 27, 2007 at 3:11 AM

I fixed the problem you got the test case for, but I'm afraid the original problem was different since my fix only involved QueryTranslator (HQL translator). I'm going to close this issue, but if the problem reappears with criteria, please tell me.

Jerome Haltom
March 21, 2007 at 8:34 AM

test case

Jerome Haltom
March 21, 2007 at 8:32 AM

Okay, I ran into this problem again, in some different code. I was able to identify the exact situation that causes the problem and create a test case. My test case may be a little broad, but it does cause the issue.

Two classes. ClassA and ClassB. ClassA contains a reference to a single instance of ClassB. ClassB contains a reference to a single instance of ClassA. In both directions, this reference may be null. On ClassB's table lives a FK pointing to ClassA's PK. ClassA's table contains no reference to ClassB.

ClassB is mapped to ClassA using a many-to-one.

ClassA is mapped to ClassB using a one-to-one, with a `property-ref` referring to the many-to-one relationship established on ClassB.

If no ClassB exists for a given ClassA, and a query is made `from ClassA a left join fetch a.B`, an exception is thrown.

Attached following this will be a zip file containing a VS2005 project configured against a local MS SQL 2005 database. I'm unsure if this is an appropriate way to package a test case, but it works for me. =) You will have to adjust the references.

Former user
February 19, 2007 at 5:35 AM

Please provide a test case. Postponing this until a test case is provided.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created February 9, 2007 at 3:36 PM
Updated March 27, 2007 at 3:11 AM
Resolved March 27, 2007 at 3:11 AM
Who's Looking?