private ILogin results;
public ILogin authenticate(Login login) {
System.out.println(login);
System.out.println(login.getEmail());
String query = "SELECT email, id FROM Login WHERE email='"
+ login.getEmail() + "' AND password='" + login.getPassword() + "'";
results = getHibernateTemplate().find(query);
System.out.println(results);
return results;
}
How do i change results = getHibernateTemplate().find(query); I get the error in this line. But i want that in ILogin type not of List type. How do i do an Type Conversion here.
The problem isn’t the type conversion per se – it’s that you’ve executed a query which may return multiple results, but you only want a single result.
You probably want to check that the resulting list has exactly one value (0 means login not found; more than 1 probably means there’s a problem in your data somewhere) and then return that first value (
return (ILogin) list.get(0);).As a slightly separate matter, you shouldn’t be including the data directly in your query like that, IMO. Use query parameters, which is pretty easy in Hibernate:
Finally, you almost certainly don’t want
resultsto be an instance variable – it should probably be a local variable, as per my example above.