Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.appfuse.dao.hibernate;
This class interacts with Spring's HibernateTemplate to save/delete and retrieve User objects.

Matt Raible Modified by Dan Kibler Extended to implement Acegi UserDetailsService interface by David Carter Modified by Bryan Noll to work with the new BaseDaoHibernate implementation that uses generics.
public class UserDaoHibernate extends GenericDaoHibernate<UserLongimplements UserDaoUserDetailsService {

Constructor that sets the entity to User.class.
    public UserDaoHibernate() {

    public List<UsergetUsers() {
        return getHibernateTemplate().find("from User u order by upper(u.username)");

    public User saveUser(User user) {
        if (.isDebugEnabled()) {
            .debug("user's id: " + user.getId());
        // necessary to throw a DataIntegrityViolation and catch it in UserManager
        return user;

Overridden simply to call the saveUser method. This is happenening because saveUser flushes the session and saveObject of BaseDaoHibernate does not.

user the user to save
the modified user (with a primary key set if they're new)
    public User save(User user) {
        return this.saveUser(user);

    public UserDetails loadUserByUsername(String usernamethrows UsernameNotFoundException {
        List users = getHibernateTemplate().find("from User where username=?"username);
        if (users == null || users.isEmpty()) {
            throw new UsernameNotFoundException("user '" + username + "' not found...");
        } else {
            return (UserDetailsusers.get(0);

    public String getUserPassword(String username) {
        SimpleJdbcTemplate jdbcTemplate =
                new SimpleJdbcTemplate(SessionFactoryUtils.getDataSource(getSessionFactory()));
        Table table = AnnotationUtils.findAnnotation(User.classTable.class);
        return jdbcTemplate.queryForObject(
                "select password from " + + " where username=?"String.classusername);
New to GrepCode? Check out our FAQ X