tags:

views:

158

answers:

1

0 vote down star

I have used hibernate to fetch the login information from the mysql database. But the problem is that say for example the user name is 'dhiraj' in the database, now the login is successful by entering the user name, but it is also allowing to enter by taking the user name in uppercase also, e.g., 'DHIRAJ'. I want to restrict it to as it in the database. Can you tell me how to achieve that in hibernate?

+1  A: 

I don't think hibernate is the matter here.

What database are you using ? (you should retag your question to add at least the db implementation you are using).

For example mysql do not do case sensitive comparison by default. Look here : http://mysqldatabaseadministration.blogspot.com/2006/09/case-sensitive-mysql.html on how to make mysql do case sensitive comparison.

EDIT: like said in the link i've pasted, you can do it at the table creation, by setting a special character set, like that :

###########
# Start case sensitive collation example
###########

mysql> create table case_cs_test (word VARCHAR(10)) CHARACTER SET latin1 COLLATE latin1_general_cs;
Query OK, 0 rows affected (0.08 sec)

mysql> INSERT INTO case_cs_test VALUES ('Frank'),('Google'),('froogle'),('flickr'),('FlicKr');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM case_cs_test WHERE word  LIKE 'F%';
+---------+
| word    |
+---------+
| Frank   |
| FlicKr  |
+---------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM case_cs_test WHERE word  LIKE 'f%';
+---------+
| word    |
+---------+
| froogle |
| flickr  |
+---------+
2 rows in set (0.00 sec)

###########
# end
###########
Thierry
Ya I am using mysql database only and I had not found any way how to achieve the case sensitive problem, actually at first I thought that it was a problem of hibernate, but as you pointed it might be the case of mysql. Now can you tell me at the database level how can we check that?
dhiraj
Can you tell me whether I can set this at the mysql level so that the hibernate always selects the user_id column of the user table as case sensitive only?
dhiraj
i've edited my answer.
Thierry
Thanx Henry for your reply.
dhiraj