0

I have a simple login page username is "Admin" and password is "hello" but criteria function accepts all values like "HELlo" "HELLO" this types. I want to only accept case sensitive result. what can i do any one please help me.

public Members logIn(Members members) {
    Criteria criteria = sessionFactory
        .getCurrentSession().createCriteria(Members.class);
    criteria.add(Expression.eq("memberUserName", members.getMemberUserName()));
    criteria.add(Expression.eq("password", members.getPassword()));

    Members Member=(Members) criteria.uniqueResult();
    return Member;
}

model class:

@Entity
@Table(name="Members")
public class Members{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "memberId")
    private int memberId;

    @Column(name="memberUserName", unique=true)
    private String memberUserName;

    @Column(name="passwrd")
    private String password;

    @Column(name="memberName")
    private String memberName;
}
veljkost
  • 1,748
  • 21
  • 25
Manihtraa
  • 968
  • 3
  • 12
  • 28
  • Possible duplicate of [Case-insensitive equals using Hibernate Criteria](http://stackoverflow.com/questions/624604/case-insensitive-equals-using-hibernate-criteria) (check the more recent answers, the accepted one is deprecated now) – AxelH Feb 06 '17 at 13:51
  • Seems he wants to be case sensitive when your link is case insensitive. Suprised Hibernate would be case insensitive by default though ? – TheBakker Feb 06 '17 at 13:52
  • @TheBakker Indeed, but same surprise to be honnest ^^ I should check that, I don't remember it to be case insensitve... This could be depending on the DB used actually (well the encoding) – AxelH Feb 06 '17 at 13:55
  • Maybe the column definition in the database is case insensitive? – Redlab Feb 06 '17 at 13:56
  • How to check db. it is case insensitive? – Manihtraa Feb 06 '17 at 14:05
  • What database are you using @Manihtraa? – Naros Feb 06 '17 at 14:54
  • MYSQL workbench 6.3 @Naros – Manihtraa Feb 07 '17 at 05:43

1 Answers1

0

MySQL by default uses case insensitive collations. You either need set the database collation so that it's entirely case sensitive or you need to apply a custom column definition that specifies a column specific collation for case sensitivity.

See this post.

Community
  • 1
  • 1
Naros
  • 19,928
  • 3
  • 41
  • 71
  • how can i do this in hibernate criteria? – Manihtraa Feb 07 '17 at 06:03
  • You cannot do this as part of the Criteria API. This is something you have to do either as part of the `@Column(columnDefinition="...")` configuration or you need to manipulate the table column manually. – Naros Feb 07 '17 at 14:09