title: Hibernate stops at DAO query
body: <p>The problem is, when i go the the login page, type an username/password to login I get an error even if i wrote them correctly (I checked my database and the entries exist).
  I know i should of used a Logger but i'm still learning the Spring Framework with Hibernate.  </p>
  
  <p>EDIT :<br>
  1.first part of the test i entered an empty username/password(and it works for empty/empty). For the second part i used one that <em>should</em> work.<br>
  2.Other DAOs work correctly with Hibernate (e.g. they retrieve the data correctly and i have no problem with them)  </p>
  
  <p>The console output looks like this:</p>
  
  <pre><code>-----------------------------------
  User Service INVOKED
  User Service-- searching for User:
  DAO-- Searching for:
  Hibernate: select this_.id as id9_0_, this_.accountName as accountN2_9_0_, this_.password as password9_0_, this_.secGrade as secGrade9_0_, this_.userEmail as userEmail9_0_, this_.userName as userName9_0_ from USER this_ where this_.accountName=?
  DAO-- End search
  DAO--Not found
  User Service-- UserProxyImpl instantiated
  User Service-- NOT FOUND,
  null
  true //&lt;-- Error returned to the controller
  -----------------------------------
  User Service INVOKED
  User Service-- searching for User:admin
  DAO-- Searching for:admin
  Hibernate: select this_.id as id9_0_, this_.accountName as accountN2_9_0_, this_.password as password9_0_, this_.secGrade as secGrade9_0_, this_.userEmail as userEmail9_0_, this_.userName as userName9_0_ from USER this_ where this_.accountName=?
  UserService-- Error in retrieving user
  // It stops here and i don't understand why
  true // still, returns error to the controller.
  </code></pre>
  
  <p>Is this a session timeout problem?</p>
  
  <p>Method from the Login Controller:</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.GET)
      public String Login(@RequestParam(value="error", required=false) boolean error,ModelMap model) {
  
          if (error == true) {
              model.put("error", "You have entered an invalid username or password!");
          } else {
              model.put("error", "");
          }
          System.out.println(error);
          return "login";     
  
      }
  </code></pre>
  
  <p>The User Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "USER")
  public class User implements Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = -1963505165125499005L;
  
  
      private long id;
      private int secGrade;
  
      private String userName;
      private String accountName;
      private String password;
      private String userEmail;
  
      public User(String name,
                  String user_name,
                  String password,
                  String email,
                  int secGrade){
          this.userName = name;
          this.accountName = user_name;
          this.password = password;
          this.userEmail = email;
          this.secGrade = secGrade;
      }
  
      @Id
      @GeneratedValue
      public long getId() {
          return id;
      }
      public void setId(long id) {
          this.id = id;
      }
      public int getSecGrade() {
          return secGrade;
      }
      public void setSecGrade(int secGrade) {
          this.secGrade = secGrade;
      }
  
      public String getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public String getAccountName() {
          return accountName;
      }
  
      public void setAccountName(String accountName) {
          this.accountName = accountName;
      }
  
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getUserEmail() {
          return userEmail;
      }
  
      public void setUserEmail(String userEmail) {
          this.userEmail = userEmail;
      }
  
  }
  </code></pre>
  
  <p>Proxy class used for handling DB Entity:</p>
  
  <pre><code>public class UserProxyImpl implements UserProxy {
  
      private int secGrade;   
      private String name;
      private String user_name;
      private String password;
      private String email;
  
      public UserProxyImpl() { }
  
      public UserProxyImpl(User usr){
          if( usr != null){
              System.out.println("USER PROXY--- constru from "+usr.getAccountName());
              this.secGrade = usr.getSecGrade();
              this.name = usr.getUserName();
              this.user_name = usr.getAccountName();
              this.password = usr.getPassword();
              this.email = usr.getUserEmail();
          }
      }
  + GETTERS/SETTERS
  }
  </code></pre>
  
  <p>Methods from the UserServiceImpl, which create the User obj and adds Authorities:</p>
  
  <pre><code>@Override
          public UserDetails loadUserByUsername(String username) 
                  throws UsernameNotFoundException,DataAccessException {
                  // Declare a null Spring User
                  UserDetails user = null;
                  System.out.println("-----------------------------------");
                  System.out.println("User Service INVOKED");
  
  
              try {
                  System.out.println("User Service-- searching for User:"+username);
                 // Search database for a user that matches the specified username
                  UserProxyImpl dbUser = new UserProxyImpl(userDAO.searchDB(username));
                  System.out.println("User Service-- UserProxyImpl instantiated");
                  if(dbUser.getName() != null){
                      System.out.println("User Service-- FOUND,"+username);
                  }
                  else{
                      System.out.println("User Service-- NOT FOUND,"+username);
                  }
  
                 // Populate the Spring User object with details from the dbUser
                 // getAuthorities() will translate the access level to the correct role type
                  System.out.println(dbUser.getName());
                  user = new User(
                          dbUser.getUser_name(),
                          dbUser.getPassword().toLowerCase(),
                          true,
                          true,
                          true,
                          true,
                          getAuthorities(new Integer(dbUser.getSecGrade()))
                          );
                  System.out.println(user.toString());
                } catch (Exception e) {
                 System.out.println("UserService-- Error in retrieving user");
                 throw new UsernameNotFoundException("Error in retrieving user");
                }
  
                // Return user to Spring for processing.
  
                return user;
               }
  
  
           @Override
          public Collection&lt;GrantedAuthority&gt; getAuthorities(Integer access) {
                 // Create a list of grants for this user
                 List&lt;GrantedAuthority&gt; authList = new ArrayList&lt;GrantedAuthority&gt;(2);
  
                 // All users are granted with ROLE_USER access
  
                 authList.add(new GrantedAuthorityImpl("ROLE_USER"));
  
                 // Check if this user has admin access
                 // We interpret Integer(3) as an admin user
                 if ( access.compareTo(3) == 0) {
  
                      authList.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
  
                 }
                 else if ( access.compareTo(2) == 0) {                
  
                     authList.add(new GrantedAuthorityImpl("ROLE_MOD"));
                 }
  
                 // Return list of granted authorities
                 return authList;
                 }
  </code></pre>
  
  <p>DAO class method used for retrieving an object from the DB:</p>
  
  <pre><code>public User searchDB(String username){
  
          User u = (User)this.getSessionFactory().getCurrentSession()
                      .createCriteria(User.class)
                      .add(Restrictions.eq("accountName",username))
                      .uniqueResult();
          System.out.println("DAO-- End search");
          if(u != null){
              System.out.println("DAO-- Found:"+u.getUserName());
              return u;
          }
          else{
              System.out.println("DAO--Not found");
              return null;
          }
  
      }
  </code></pre>
  
  <p>Spring Security config. XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans 
      xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
                          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://www.springframework.org/schema/security 
                          http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  
   &lt;http auto-config = 'true' use-expressions="true" access-denied-page="/denied" &gt;
  
      &lt;intercept-url pattern = "/home/" access="permitAll"/&gt;
      &lt;intercept-url pattern = "/home/login" access="permitAll"/&gt;
      &lt;intercept-url pattern = "/home/jobs" access="permitAll"/&gt;
      &lt;intercept-url pattern = "/home/info" access="permitAll"/&gt;
      &lt;intercept-url pattern = "/home/common" access="hasRole('ROLE_USER')"/&gt;
      &lt;intercept-url pattern = "/home/desk" access="hasRole('ROLE_MOD')"/&gt;
      &lt;intercept-url pattern = "/home/admin" access="hasRole('ROLE_ADMIN')"/&gt;
      &lt;form-login login-page="/login"
                  default-target-url="/home"
                  authentication-failure-url="/home/login?error=true"/&gt;
      &lt;logout logout-success-url="/home" /&gt;               
   &lt;/http&gt; 
  
   &lt;authentication-manager alias="authenticationManager"&gt;
      &lt;authentication-provider ref="authenticationProvider"/&gt;
  &lt;/authentication-manager&gt;
  
  &lt;beans:bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
      &lt;beans:property name="userDetailsService" ref="UserServiceImpl"/&gt;
  &lt;/beans:bean&gt;
  
  
   &lt;!-- Use a Md5 encoder  --&gt;
   &lt;beans:bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/&gt;
  
   &lt;!-- A custom service where Spring will retrieve users and their corresponding access levels  --&gt;
   &lt;beans:bean id="UserServiceImpl" class="com.x.interview_management.service.impl.UserServiceImpl"/&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Login.jsp:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ page session="false" %&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  &lt;%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;${error}&lt;/h1&gt;
      &lt;sec:authorize access="!isAuthenticated()"&gt;
      &lt;div id = "login" style="text-align:center;"&gt;
  
                  &lt;h3 style="text-align:center"&gt;Login with Username and Password&lt;/h3&gt;
  
                      &lt;form action='/InterviewManagement/j_spring_security_check' method='POST'&gt;
                      &lt;table&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Username:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='text' name='j_username' value=''&gt;&lt;td/&gt;
                      &lt;tr/&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Password:&lt;/td&gt;
                          &lt;td&gt;&lt;input type='password' name='j_password'/&gt;&lt;td/&gt;
                      &lt;tr/&gt;
  
                      &lt;tr&gt;
                          &lt;td&gt;&lt;input name="submit" type="submit"/&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input name="reset" type="reset"/&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;/table&gt;
                      &lt;/form&gt;
  
      &lt;/div&gt;
      &lt;/sec:authorize&gt;    
      &lt;a href="/InterviewManagement/home/"&gt;return home&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Sorry about the code layout, it's my first time posting on StackExchange.</p>