L.Anush
L.Anush

Reputation: 101

Why Hibernate Criteria projection Return a Null Object?

What i want is to send Mobile number to the database and fetch Customer object. i debug following code and saw null customer object returned. Any help?

 public Customer unSuccessfulLoginAttempts(String mobileNumber) {
    log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<| Unsuccessful Logging Attempts  Repository Starting|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> {}" ,mobileNumber );
    Session session = entityManager.unwrap(Session.class);
    Criteria criteria = session.createCriteria(Customer.class,"c");
    Criterion mobile = Restrictions.eq("c.phone1",mobileNumber);
    criteria.add(Restrictions.eq("u.phone1", mobileNumber));
    return (Customer) criteria.list();
}

Upvotes: 1

Views: 489

Answers (1)

Alexander Petrov
Alexander Petrov

Reputation: 9492

From what I can see your alias is "c" but you are using "u". You need to have:

List customer = session.createCriteria(Customer.class)
                           .add(Restrictions.eq("phone1", mobileNumber))
                           .list();

Also your variable mobile remains unused.

Upvotes: 1

Related Questions