1

This is my HQL Query

Query query = getCurrentSession().createQuery(
            "from User where username = :usersName ");
    query.setParameter("usersName", usersName);

Now if the user name contains dot'.' character its returning empty set other wise its returning the user details.

What I have tried?

Hibernate having difficulty with '@' character in HQL

Executed the sql query in the server its returning the user details.

Concatenated the parameters directly in query string getting same error.

Tried Criteria Query Got the same problem

where might be the problem?

Community
  • 1
  • 1
smali
  • 4,687
  • 7
  • 38
  • 60
  • The problem might be a leading or trailing space or something similar. If you do a "from User where username LIKE :usersName" and set `usersName` to the same thing but replacing `@` by `%` what do you get? –  Jan 05 '16 at 07:05
  • Try the "like", if it works, then the issue is the `@` –  Jan 05 '16 at 08:26
  • If by same result you mean with the like you get no results, then the issue is not the `@` –  Jan 05 '16 at 08:40
  • Yes exactly its the problem of dot `.` not the `@` character. I directly tested by changing the values in database – smali Jan 05 '16 at 08:50
  • Maybe your dot (in DB) is some kind of unicode dot, not an ascii one. –  Jan 05 '16 at 10:42
  • yeah might be, but the encoding of mssql is SQL_Latin1_General_CP1_CI_AS so basically it means ascii http://stackoverflow.com/questions/5039211/what-does-collate-sql-latin1-general-cp1-ci-as-do , Might be hibernate is using some other encoding will verify it once – smali Jan 05 '16 at 12:45

2 Answers2

0

Try to use this: query.setString("usersName", usersName);

Idos
  • 15,053
  • 14
  • 60
  • 75
0

You can try this:

query.setString("usersName", usersName.replaceAll("@", "/@"));
liuruizhi
  • 1
  • 1