Case sensitive on restrictions 'equals id' in Hibernate restrictions

后端 未结 2 852
忘掉有多难
忘掉有多难 2021-01-24 09:34

I try to do a case sensitive equals on username with Hibernate (3.6.9) but it seems that the restriction is case insensitive.
For example: \"AdMin\" or \"admin\

相关标签:
2条回答
  • 2021-01-24 10:11

    A simple workaround:

        Login login = (Login) getHibernateTemplate().get(Login.class, username);
        if(login != null && !login.getUsername().equals(username)){
            return null;
        }
        return login;   
    
    0 讨论(0)
  • 2021-01-24 10:27

    I think you need to change table definition. In case of Mysqsl you need to alter your username column to binary or varbinary instead of char/varchar (http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html). For SQLServer, make sure username uses case-sensitive collation (see list of sql collations)

    0 讨论(0)
提交回复
热议问题