The Javadoc for IdentifierLoadAccess
is pretty clear in how the load
method should behave:
Return the persistent instance with the given identifier, or null if there is no such persistent instance.
This means it should return just one object, not a List
of objects. Try casting it to T
instead.
If you want to query your entity (that is, retrieve items by any other means than primary key), you most likely want to implement the search(String)
method.
If you want to query your entity (that is, retrieve items by any other means than primary key), take a look at the UserDaoHibernate
that is shipped with AppFuse. It contains a method loadUserByUsername()
which is implemented like this:
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
List users = getSession().createCriteria(User.class).add(Restrictions.eq("username", username)).list();
if (users == null || users.isEmpty()) {
throw new UsernameNotFoundException("user '" + username + "' not found...");
} else {
return (UserDetails) users.get(0);
}
}
Obviously, if you want to return all items, it should be modified a bit (this one is made up):
public List<UserDetails> loadLockedUsers() {
List<UserDetails> users = (List<UserDetails>) getSession().createCriteria(User.class).add(Restrictions.eq("account_locked", true)).list();
return users;
}