last day (14 days later) » 

1:51 PM
1
A: NHibernate: Select item with entry in element bag

Radim KöhlerAlmost the same answer I just gave to previous NHibernate question: QueryOver IList<string> property Based on this Q & A: NHibernate How do I query against an IList property? Where I tried to show that (as mentioned in the documentation) we can use magical word ".elements": 17.1.4.1. Alias and...

 
Thanks a lot. But I get an SQL-Error, because the join alias (... inner join tblPaperboyAdditionalPhoneNumbers additiona4_ on ...) does not match the used property prefix (additional1_.PhoneNumber). Is it a bug in NHibernate? In the sample some many-to-ones are left out in the mapping.
 
That is weird, because if you used alias criteria.CreateAlias("_additionalPhoneNumbers", "AdditionalPhoneNumbers"); it should now be working with restriction (Restrictions.Eq("AdditionalPhoneNumbers.elements", number). I did test that locally. Could you show me your latest code? and add the exception full stack trace? I am sure we will make it.
 
Added current code to the post. As I said, the original Paperboy-class has another property mapped as many-to-one.
 
will check give me few mintues
I am using NHibernate 4.0.2 and I followed your model and that is my query by NHibernate exec sp_executesql N'SELECT this_.Id as Paperboy1_39_1_ FROM tblPaperboy this_ inner join tblPaperboyAdditionalPhoneNumbers apn1_ on this_.PaperboyId=apn1_.PaperboyId WHERE (apn1_.PhoneNumber = @p0) ORDER BY CURRENT_TIMESTAMP OFFSET 0 ROWS FETCH FIRST @p1 ROWS ONLY',N'@p0 nvarchar(4000),@p1 int',@p0=N'abc',@p1=1 is this working wheny ou try to execute that - because for me it is working
 
I am (shockingly) using NHibernate 3.0. I will update to 3.2 and check if it still doesnt work. By the way, I added the produced sql to the post. Exception is still the same.
 
1:51 PM
We do have a progress ;) and soon we will have solution ;) BTW, important note - I migrated from 3 to 4.0 without any issues. Maybe - you should do the same. Really
 
The problem is with spring.net which has only libraries for NH 3.2.
 
I see... let's use just 3.2
The main issue here is, that I reproduced your scenario locally and it is working. So if you showed me your code.. then it must be working as I described...
As I say, Not only I know it is working - I really tested ;)
 
Did you add a many to one?
Did you reproduce it with NH 4.0 or 3.2?
 
many to one? there is no many to one
and yes I am in 4.0
but there is only one to many
 
<many-to-one name="_agency"
class="Agency"
access="field"
column="AgencyKey" />
 
2:00 PM
Is not that brand new?
check your question
there is no Agency... just a List<string>
 
As I said, the sample is not complete. I simplified it to keep eyes on the problem
 
;) Wel Tobias please
trust me, that your simplified scenario could be solve the way I should you
I can hardly do more here, without all your code.. but that is a bit over my abilities
I would strongly suggest: Try to reduce your mapping to degree in your question, and try my anser. it should work
 
So is the additional many-to-one a problem?
 
next try to extedn.. and you will se hwer the problem is
Not sure... could be
 
I can exclude the mapping for agency and rerun the test.
Without Agency:
SELECT TOP (@p0) this_.Id as Id3_0_, this_.BusinessId as BusinessId3_0_, this_.Lastname as Lastname3_0_, this_.Firstname as Firstname3_0_, this_.Title as Title3_0_, this_.Street as Street3_0_, this_.Zip as Zip3_0_, this_.City as
 
2:06 PM
Working or not?
(your snippet is missing FROM and JOIN
 
The snippet is sql output of the testcase/nhibernate
ErrorCode [4104]; Der mehrteilige Bezeichner 'apn1_.PhoneNumber' konnte nicht gebunden werden. ---> System.Data.SqlClient.SqlException: Der mehrteilige Bezeichner 'apn1_.PhoneNumber' konnte nicht gebunden werden.
 
read it above.. it is not compelte
FROM is missing
 
SELECT TOP (@p0) this_.Id as Id3_0_, this_.BusinessId as BusinessId3_0_, this_.Lastname as Lastname3_0_, this_.Firstname as Firstname3_0_, this_.Title as Title3_0_, this_.Street as Street3_0_, this_.Zip as Zip3_0_, this_.City as City3_0_, this_.Phone as Phone3_0_, this_.Mobile as Mobile3_0_,
this_.Comment as Comment3_0_, this_.StaffId as StaffId3_0_, this_.IsActive as IsActive3_0_ FROM tblPaperboy this_ inner join tblPaperboyAdditionalPhoneNumbers additiona3_ on this_.Id=additiona3_.PaperboyId WHERE (apn1_.PhoneNumber = @p1)
 
check this
tblPaperboyAdditionalPhoneNumbers additiona3_ on this_.Id=additiona3_.PaperboyId
JOIN Seems to be awesome
 
I see. But it is the sql hibernate produces
 
2:09 PM
there is no apn1_.PhoneNumber'
NO NO NO
check the SQL
there is no part apn1_.PhoneNumber'
SQL is ok... some other sql is wrong
try to take that and run... I am sure it wil work
 
If I correct the sql, it runs successfully.
But as I said: the sql you see is the one produced from hibernate
 
You must upgrade
that is the solution
 
Hmmmm
Or change the mapping from IList<string> to a separate entity.
 
yes ;)
that would be the best... really
I do use only many-to-one, one-to-many... all is working and easy to generalize...
have to go...
if anyhting... leave a comment
good luck with NHibernate
 

last day (14 days later) »