I am trying to get some specific columns using hibernate, but this query always fails.
@Override
public Users findByEmail(String emailID) {
// TODO Auto-generated method stub
try{
List<Users> users = new ArrayList<Users>();
users = this.sessionFactory.getCurrentSession().createQuery("SELECT userID, firstName, lastName, imageURL, password, emailID, enabled FROM Users WHERE emailID = :email_ID")
.setParameter("email_ID", emailID).list();
if(users.size() > 0)
return (Users)users.get(0);
else
return null;
}
catch(Exception exc)
{
log.error(exc.getMessage());
return null;
}
}
This query always fails, so I use the below query
@Override
public Users findByEmail(String emailID) {
// TODO Auto-generated method stub
try{
List<Users> users = new ArrayList<Users>();
users = this.sessionFactory.getCurrentSession().createQuery("FROM Users WHERE emailID = :email_ID")
.setParameter("email_ID", emailID).list();
if(users.size() > 0)
return (Users)users.get(0);
else
return null;
}
catch(Exception exc)
{
log.error(exc.getMessage());
return null;
}
}
How can I get only specific columns using hibernate rather than getting 20s of columns?