title: Exception : org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
body: <p>I am working on a application in which hibernate  and postgresql and giving the following error</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"</p>
  </blockquote>
  
  <p>Can someone tell me where I am going wrong. I am using Postgres 9.4.</p>
  
  <pre class="lang-none prettyprint-override"><code> HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
  
  
      type Exception report
  
      message Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
  
      description The server encountered an internal error that prevented it from fulfilling this request.
  
      exception 
      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
          org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
          org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
          javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
          org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  
  
      root cause 
      org.hibernate.exception.SQLGrammarException: could not get next sequence value
          org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
          org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  
      ...
  
      root cause 
      org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
        Position: 1
          org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2161)
          org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1890)
          org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
          org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559)
          org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
          org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
          org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75)
          org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:58)
          org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
          org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
          org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
          org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
          org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
          org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
          org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
          org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
          com.dineshonjava.dao.EmployeeDaoImpl.addEmployee(EmployeeDaoImpl.java:22)
          com.dineshonjava.service.EmployeeServiceImpl.addEmployee(EmployeeServiceImpl.java:26)
  </code></pre>
  
  <p><strong>EmployeeController</strong>       </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.techprep.bean.EmployeeBean;
  import com.techprep.model.Employee;
  import com.techprep.service.EmpService;
  
  @Controller
  public class EmployeeController {
      @Autowired
      private EmpService empService;
  
  
       @RequestMapping("/addEmployee")
       public ModelAndView showForm(){
             // return new ModelAndView("addEmployee");
              return new ModelAndView("addEmployee","emp",new EmployeeBean());  
       }
  
      @RequestMapping(value="/save", method=RequestMethod.POST)
      public ModelAndView saveEmployee(@ModelAttribute("emp")EmployeeBean employeeBean, 
                 BindingResult result) {
                Employee employee = prepareModel(employeeBean);
                empService.addEmployee(employee);
                return new ModelAndView("success");
               }
  
      @RequestMapping(value="/employees", method = RequestMethod.GET)
       public ModelAndView listEmployees() {
        Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
        model.put("employees",  prepareListofBean(empService.listEmployeess()));
        return new ModelAndView("employeesList", model);
       }
  
      @RequestMapping(value = "/delete", method = RequestMethod.GET)
      public ModelAndView editEmployee(@ModelAttribute("command")EmployeeBean employeeBean,
         BindingResult result) {
          empService.deleteEmployee(prepareModel(employeeBean));
        Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
        model.put("employee", null);
        model.put("employees",  prepareListofBean(empService.listEmployeess()));
        return new ModelAndView("addEmployee", model);
       }
  
      private Employee prepareModel(EmployeeBean employeeBean){
            Employee employee = new Employee();
            employee.setEmpAddress(employeeBean.getAddress());
            employee.setEmpAge(employeeBean.getAge());
            employee.setEmpName(employeeBean.getName());
            employee.setSalary(employeeBean.getSalary());
            employee.setEmpId(employeeBean.getId());
            employeeBean.setId(null);
            return employee;
           }
  
      private List&lt;EmployeeBean&gt; prepareListofBean(List&lt;Employee&gt; employees){
            List&lt;EmployeeBean&gt; beans = null;
            if(employees != null &amp;&amp; !employees.isEmpty()){
             beans = new ArrayList&lt;EmployeeBean&gt;();
             EmployeeBean bean = null;
             for(Employee employee : employees){
              bean = new EmployeeBean();
              bean.setName(employee.getEmpName());
              bean.setId(employee.getEmpId());
              bean.setAddress(employee.getEmpAddress());
              bean.setSalary(employee.getSalary());
              bean.setAge(employee.getEmpAge());
              beans.add(bean);
             }
            }
            return beans;
           }
  
      @RequestMapping(value="/show")
      public String show(){
          return "show";
      }
  
  }
  </code></pre>
  
  <p><strong>Employee.java Class</strong></p>
  
  <pre><code>  import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
  
  
  
  
  
      @Entity
      @Table(name="Employee")
      public class Employee {
           @Id
           @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="empsequence")
           @SequenceGenerator(name ="empsequence", sequenceName="empsequence")
           @Column(name = "empid")
           private Integer empId;
  
           @Column(name="empname")
           private String empName;
  
           @Column(name="empaddress")
           private String empAddress;
  
           @Column(name="salary")
           private Long salary;
  
           @Column(name="empAge")
           private Integer empAge;
  
          public Integer getEmpId() {
              return empId;
          }
  
          public void setEmpId(Integer empId) {
              this.empId = empId;
          }
  
          public String getEmpName() {
              return empName;
          }
  
          public void setEmpName(String empName) {
              this.empName = empName;
          }
  
          public String getEmpAddress() {
              return empAddress;
          }
  
          public void setEmpAddress(String empAddress) {
              this.empAddress = empAddress;
          }
  
          public Long getSalary() {
              return salary;
          }
  
          public void setSalary(Long salary) {
              this.salary = salary;
          }
  
          public Integer getEmpAge() {
              return empAge;
          }
  
          public void setEmpAge(Integer empAge) {
              this.empAge = empAge;
          }
      }
  </code></pre>