-->
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: HQL bug
PostPosted: Wed Jan 30, 2008 2:35 am 
Newbie

Joined: Thu Apr 13, 2006 1:56 am
Posts: 11
NHibernate version:
1.2.1.4000

HQL:
... FROM User u WHERE u.UserName=N'test'

Throw sqlException: Incorrect syntax near 'test'

The generated SQL (show_sql=true):

... WHERE u.UserName=N 'test'

A blank come Between "N" and "test", it is Incorrect.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 3:42 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Sorry can't help because I have no Idea what

u.UserName=N'test'

is supposed to mean. What does the N before the string literal do and on what kind of db?

just curious
Jens

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 5:42 am 
Newbie

Joined: Thu Apr 13, 2006 1:56 am
Posts: 11
schauder wrote:
Sorry can't help because I have no Idea what

u.UserName=N'test'

is supposed to mean. What does the N before the string literal do and on what kind of db?

just curious
Jens



I use sql server 2005 and it support sql like "Select * from User where UserName = N'Unicode'". because we use the character collation need support unicode.

So I want the hql to search user with unicode, but hql do not throw the syntax exception of "u.UserName=N'test' ", but the generated sql is
u.UserName=N 'test'.
it has a space between the N and 'test' and can not run on sql server.

Is it a hibernate syntax validation bug or generated sql bug?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 8:36 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
You shouldn't be constructing queries that way anyway. Use parameters instead. The parameter should automatically be passed as an NVarchar to SQL Server, therefore you don't have to worry about the syntax.

"u.UserName = :userName" is all you need. Then just call SetParameter() on your query object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 9:40 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
thanks jchapman ,

your solution solved this problem greatly .


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.