title: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
body: <p>When i run my project then I am getting error</p>
  
  <blockquote>
    <p><code>hibernate.dialect</code> must be set when no Connection available</p>
  </blockquote>
  
  <p>with this stack trace</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:241)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>I am not able to understand from where this error is coming. my servlet.xml is</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
      &lt;context:annotation-config/&gt;
      &lt;context:component-scan base-package="com.csc.StudentAdmission" /&gt;
      &lt;mvc:annotation-driven/&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/"/&gt;
      &lt;bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" &gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name ="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="jdbc:postgresql://localhost:5432/hibernatedb;create=true" /&gt;
          &lt;property name="username" value="postgres" /&gt;
          &lt;property name="password" value="root" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan" value="com.csc.StudentAdmission"&gt;&lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
                  &lt;!-- &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt; --&gt; 
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>my DAo file is </p>
  
  <pre><code>package com.csc.student.DAO;
  
  import java.util.List;
  
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  
  import com.csc.StudentAdmission.Student;
  
  public class StudentInfo {
      @Autowired
      SessionFactory sessionFactory;
  
      public StudentInfo(){   
      }
  
      public SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
  
      public boolean saveStudentInfoIntoDB(Student student){
  
          Session session = getSessionFactory().openSession();
  
          session.beginTransaction();
  
          String hql = "FROM Student WHERE userName='" + student.getUserName()+ "' or rollNo='" + student.getRollNo() + "'";
  
          Query query = session.createQuery(hql);
  
          @SuppressWarnings("unchecked")
          List&lt;Student&gt; results = query.list();
  
          if (!results.isEmpty()) {
              return false;
          }
  
          session.save(student);
          session.getTransaction().commit();
          // closing the session
  
          session.close();
          return true;
      }
      public Student processLoginForm(String userName, String password){
  
          Session session = getSessionFactory().openSession();        
          session.beginTransaction();
  
          String hql = "FROM Student WHERE userName='"+userName+"' and password='"+password+"'";
  
          Query query = session.createQuery(hql);
  
          @SuppressWarnings("unchecked")
          List&lt;Student&gt; results = query.list();
  
          if(!results.isEmpty()){
              Student student = new Student();
              student =results.get(0);
              System.out.println(student.getFirstName());
              return student;
          }
          else 
              return null;
      }
  }
  </code></pre>
  
  <p>Entity name is also Student. Hence there is no fault in table name. but still this problem is coming. Can Someone solve my problem.</p>