title: How to check username and password from database using HIbernate in spring MVC?
body: <p>I have made a login application using SPRING MVC with annotations. I am not 
  being able to verify the username and password from the database, created in
  phpmyadmin using Hibernate.</p>
  
  <p>Below is my code</p>
  
  <pre><code>package Repository;
  
  import java.util.Iterator;
  import java.util.List;
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.AnnotationConfiguration;
  import LoginDao.LoginPojo;
  import Repository.User;
  
  @SuppressWarnings("deprecation")
  public class UserMain { 
      private static SessionFactory sf;
      public void setup() {
          try {
              sf = new AnnotationConfiguration().configure()
                      .addPackage("com.registration.domain")
                      .addAnnotatedClass
              (User.class).buildSessionFactory();
  
              } catch (Throwable e) {
              System.out.println(e);
          }
      }
  
      void verifyUser(String usernm,String passwd)
      {
           Session session = sf.openSession();
            Transaction tx = null;
            try{
               tx = session.beginTransaction();
               List&lt;?&gt; lst = session.createQuery("FROM LoginPojo").list(); 
               for (Iterator&lt;?&gt; iterator = 
                                 lst.iterator(); iterator.hasNext();){
                   LoginPojo lpojo = (LoginPojo) iterator.next(); 
                  System.out.print("Username: " + lpojo.getUsernm()); 
                  System.out.print(" Password: " + lpojo.getPasswd());                
                  if(lpojo.getUsernm().equals(usernm)&amp;&amp; lpojo.getPasswd().equals(passwd))
                  {
                      System.out.println("Correct username and password");
                  }
                  else
                  {
                      System.out.println("Incorrect username and password");
                  }
               }
               tx.commit();
            }catch (HibernateException e) {
               if (tx!=null) tx.rollback();
               e.printStackTrace(); 
            }finally {
               session.close(); 
            }
      }
  }
  </code></pre>