-->
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.  [ 4 posts ] 
Author Message
 Post subject: IQuery.SetParameterList() - Malformed SQL
PostPosted: Tue Oct 31, 2006 10:01 pm 
Newbie

Joined: Sun Aug 28, 2005 10:54 pm
Posts: 14
Hello,

The nHibernate JIRA is currently inaccessible, and I couldn't find any mention of this issue on the forum or by searching cached pages of the JIRA.

Name and version of the database you are using:
SQL Server 2000

Hibernate version:
1.0.2

Code between sessionFactory.openSession() and session.close():
IList mappedObjectCollection = session.CreateCriteria(typeof(T)).List();

session.CreateQuery("from T t where t in :objectsToLoad")
.SetParameterList("objectsToLoad", mappedObjectCollection, NHibernateUtil.Entity(typeof(T)))
.List();


The mapping of the T class uses the GUID generator for its primary key, mapped to a property called "Key". When I execute the code with the SetParameterList directive, I notice that the generated SQL is incorrect (see below). I've replaced the selected columns of the T with '*' class for brevity.

The generated SQL (show_sql=true):

exec sp_executesql
N'select * from T t0_ where (t0_.Key in @p0 , @p1 , @p2)',
N'@p0 uniqueidentifier,@p1 uniqueidentifier,@p2 uniqueidentifier',
@p0 = 'F44B4D98-311C-4800-B600-9C7499C7AF22',
@p1 = '36FFAC14-61F7-4673-985C-7DF8BE21D9AC',
@p2 = 'A7EBCDB0-36C2-48D3-B8DD-9CE56568BD56'


Note the first parenthesis in the where clause -- it is in the wrong location. The parenthesis should be between the 'in' directive and the first parameter.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 8:45 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
Hi,

Did you executed it?
If so, what happens?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 2:38 pm 
Newbie

Joined: Sun Aug 28, 2005 10:54 pm
Posts: 14
anuarneto wrote:
Hi,

Did you executed it?
If so, what happens?


Yes, I executed the code. The SQL is rejected by SQL Server with the error:
Code:
Incorrect syntax near '@p0'.


The expected syntax in the where clause is:
Code:
where t0_.Key in (@p0 , @p1 , @p2)


Top
 Profile  
 
 Post subject: Re: IQuery.SetParameterList() - Malformed SQL
PostPosted: Wed Nov 01, 2006 3:20 pm 
Newbie

Joined: Sun Aug 28, 2005 10:54 pm
Posts: 14
sguidi wrote:
session.CreateQuery("from T t where t in :objectsToLoad")
.SetParameterList("objectsToLoad", mappedObjectCollection, NHibernateUtil.Entity(typeof(T)))
.List();


Sergey was kind to note in the JIRA issue I opened that this issue is easily mitigated by enclosing the parameter ':objectsToLoad' in parentheses.

Thanks!


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