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: Criteria expression not case-sensitive?
PostPosted: Sat Jan 06, 2007 2:53 am 
Newbie

Joined: Mon Nov 07, 2005 10:09 pm
Posts: 9
Location: Milwaukee
NHibernate version: 1.2b2
Database: MSSQL2005

Hi all,

I hope this hasn't been asked... I've been unsuccessful in finding anything about it. I'm doing a simple get for a User object that matches the supplied username and password. The problem I'm having is that nHibernate is converting the specified string value to lower. For the username, that's fine, but the password should be case-sensitive. I've included a code snippet for how I'm getting the User object. Any help would be appreciated.


Code:
public User GetUserByUsernameAndPassword(string username, string password)
{
    ICriteria crit = this._activeSession.CreateCriteria(typeof(User));
    crit.Add(Expression.Eq("Username", username));
    crit.Add(Expression.Eq("Password", password));
    return crit.UniqueResult<User>();
}


Thanks

Jim

btw, I would include the nHibernate generated sql, but I'm partially stupid and fail to understand how to get it to log properly :)

_________________
Jim Geurts
CEO/Founder, Bia Creations
http://biacreations.com
Office: 414.213.1903
Fax: 414.294.3702


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 3:03 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
It's not Hibernate who makes it case insensitive, it's MSSQL.
I've never used MSSQL, but with mysql you can change the collation for a particular column from say "utf8_general_ci" to "utf8_general_bin" which would make it case sensitive.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 3:37 am 
Newbie

Joined: Mon Nov 07, 2005 10:09 pm
Posts: 9
Location: Milwaukee
Awesome, that did it. I should have known better than to blame nHibernate :)

Changing the collation from SQL_Latin1_General_CP1_CI_AS (Database default) to SQL_Latin1_General_CP1_CS_AS made it case-sensitive. Fyi to anyone else, MS has a page describing the collations: http://msdn2.microsoft.com/en-us/library/ms144250.aspx

Does anyone know if there is a way to specify this in a mapping file so that the nant task hbm2ddl will automatically generate it?

_________________
Jim Geurts
CEO/Founder, Bia Creations
http://biacreations.com
Office: 414.213.1903
Fax: 414.294.3702


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.