title: org.hibernate.exception.SQLGrammarException: could not prepare statement
body: <p>I have created two entities and am trying to fill one with data after loading it, to show it as a drop down list.</p>
  
  <p>I got the error</p>
  
  <blockquote>
    <p>org.hibernate.exception.SQLGrammarException: could not prepare statement</p>
  </blockquote>
  
  <p>The <code>Group</code> entity that must be in the drop down list is:</p>
  
  <pre><code>@Entity
  @Table(name="GROUP")
  public class Group implements Serializable,Lifecycle{
  
      /**
       * 
       */
      private static final long serialVersionUID = 5551707547269388327L;
      @Id
      @Column(name="ID")
      @GeneratedValue
      private int id;
      @Column(name="E_NAME")
      private String eName;
      @Column(name="A_NAME")
      private String aName;
  
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String geteName() {
          return eName;
      }
      public void seteName(String eName) {
          this.eName = eName;
      }
      public String getaName() {
          return aName;
      }
      public void setaName(String aName) {
          this.aName = aName;
      }
  
  
  
  
  
      @Override
      public boolean onDelete(Session arg0) throws CallbackException {
          // TODO Auto-generated method stub
          return false;
      }
      @Override
      public void onLoad(Session session, Serializable arg1) {
          // TODO Auto-generated method stub
          Group adminGroup =new Group();
          Group sectionAdminGroup =new Group();
          Group userGroup =new Group();
  
  
  
          adminGroup.seteName("Admin");
          sectionAdminGroup.seteName("Section Admin");
          userGroup.seteName("User");
  
          adminGroup.setaName("مسشرف عام");
          sectionAdminGroup.setaName("مشرف قطاع");
          userGroup.setaName("مستخدم");
  
          session.save(adminGroup);
          session.save(sectionAdminGroup);
          session.save(userGroup);
      }
      @Override
      public boolean onSave(Session arg0) throws CallbackException {
          // TODO Auto-generated method stub
          return false;
      }
      @Override
      public boolean onUpdate(Session arg0) throws CallbackException {
          // TODO Auto-generated method stub
          return false;
      }
  
  }
  </code></pre>
  
  <p>The stack trace is:</p>
  
  <blockquote>
    <p>Caused by:</p>
    
    <p>org.hibernate.exception.SQLGrammarException: could not prepare
    statement     at
    org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
      at
    org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:196)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
      at
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1884)
      at
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861)
      at
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
      at org.hibernate.loader.Loader.doQuery(Loader.java:909)     at
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
      at org.hibernate.loader.Loader.doList(Loader.java:2551)     at
    org.hibernate.loader.Loader.doList(Loader.java:2537)  at
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)    at
    org.hibernate.loader.Loader.list(Loader.java:2362)    at
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1678)   at
    org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)   at
    org.gaca.gms.dao.GenericDAOImpl.getAll(GenericDAOImpl.java:56)    at
    org.gaca.gms.services.GenericServiceImpl.getAllObjects(GenericServiceImpl.java:61)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      at
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy39.getAllObjects(Unknown Source)     at
    org.gaca.gms.controllers.UsersController.listUsers(UsersController.java:43)
      at
    org.gaca.gms.controllers.UsersController$$FastClassBySpringCGLIB$$29260f80.invoke()
      at
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at
    org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      at
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at
    org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at
    org.gaca.gms.controllers.UsersController$$EnhancerBySpringCGLIB$$de07b585.listUsers()
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      at
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      at
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      at
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      at
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      at
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)     at
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)     at
    org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at
    org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
      at
    org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at
    org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at
    org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
      at
    org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at
    org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
      at
    org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
      at
    org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:324)     at
    org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      at
    org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)  at
    org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)  at
    org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)  at
    org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      at
    org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement
    "SELECT THIS_.ID AS ID1_0_0_, THIS_.A_NAME AS A_NAME2_0_0_,
    THIS_.E_NAME AS E_NAME3_0_0_ FROM GROUP[*] THIS_ "; expected
    "identifier"; SQL statement: select this_.ID as ID1_0_0_, this_.A_NAME
    as A_NAME2_0_0_, this_.E_NAME as E_NAME3_0_0_ from GROUP this_
    [42001-178]   at
    org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
      at org.h2.message.DbException.getSyntaxError(DbException.java:204)
      at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:3024)
      at org.h2.command.Parser.readTableFilter(Parser.java:1185)  at
    org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1859)     at
    org.h2.command.Parser.parseSelectSimple(Parser.java:1968)     at
    org.h2.command.Parser.parseSelectSub(Parser.java:1853)    at
    org.h2.command.Parser.parseSelectUnion(Parser.java:1674)  at
    org.h2.command.Parser.parseSelect(Parser.java:1662)   at
    org.h2.command.Parser.parsePrepared(Parser.java:434)  at
    org.h2.command.Parser.parse(Parser.java:306)  at
    org.h2.command.Parser.parse(Parser.java:278)  at
    org.h2.command.Parser.prepareCommand(Parser.java:243)     at
    org.h2.engine.Session.prepareLocal(Session.java:442)  at
    org.h2.engine.Session.prepareCommand(Session.java:384)    at
    org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
      at org.h2.jdbc.JdbcPreparedStatement.(JdbcPreparedStatement.java:73)
      at
    org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:276)
      at
    org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
      at
    org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
      ... 73 more</p>
    
    <p>Caused by:</p>
    
    <p>org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SELECT
    THIS_.ID AS ID1_0_0_, THIS_.A_NAME AS A_NAME2_0_0_, THIS_.E_NAME AS
    E_NAME3_0_0_ FROM GROUP[*] THIS_ "; expected "identifier"; SQL
    statement: select this_.ID as ID1_0_0_, this_.A_NAME as A_NAME2_0_0_,
    this_.E_NAME as E_NAME3_0_0_ from GROUP this_ [42001-178]     at
    org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
      at org.h2.message.DbException.getSyntaxError(DbException.java:204)
      at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:3024)
      at org.h2.command.Parser.readTableFilter(Parser.java:1185)  at
    org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1859)     at
    org.h2.command.Parser.parseSelectSimple(Parser.java:1968)     at
    org.h2.command.Parser.parseSelectSub(Parser.java:1853)    at
    org.h2.command.Parser.parseSelectUnion(Parser.java:1674)  at
    org.h2.command.Parser.parseSelect(Parser.java:1662)   at
    org.h2.command.Parser.parsePrepared(Parser.java:434)  at
    org.h2.command.Parser.parse(Parser.java:306)  at
    org.h2.command.Parser.parse(Parser.java:278)  at
    org.h2.command.Parser.prepareCommand(Parser.java:243)     at
    org.h2.engine.Session.prepareLocal(Session.java:442)  at
    org.h2.engine.Session.prepareCommand(Session.java:384)    at
    org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
      at org.h2.jdbc.JdbcPreparedStatement.(JdbcPreparedStatement.java:73)
      at
    org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:276)
      at
    org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
      at
    org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:162)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
      at
    org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
      at
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1884)
      at
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861)
      at
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
      at org.hibernate.loader.Loader.doQuery(Loader.java:909)     at
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
      at org.hibernate.loader.Loader.doList(Loader.java:2551)     at
    org.hibernate.loader.Loader.doList(Loader.java:2537)  at
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)    at
    org.hibernate.loader.Loader.list(Loader.java:2362)    at
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1678)   at
    org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)   at
    org.gaca.gms.dao.GenericDAOImpl.getAll(GenericDAOImpl.java:56)    at
    org.gaca.gms.services.GenericServiceImpl.getAllObjects(GenericServiceImpl.java:61)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      at
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      at com.sun.proxy.$Proxy39.getAllObjects(Unknown Source)     at
    org.gaca.gms.controllers.UsersController.listUsers(UsersController.java:43)
      at
    org.gaca.gms.controllers.UsersController$$FastClassBySpringCGLIB$$29260f80.invoke()
      at
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at
    org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      at
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      at
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at
    org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at
    org.gaca.gms.controllers.UsersController$$EnhancerBySpringCGLIB$$de07b585.listUsers()
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)     at
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      at
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      at
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      at
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      at
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      at
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)     at
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)     at
    org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at
    org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
      at
    org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at
    org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at
    org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
      at
    org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at
    org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
      at
    org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
      at
    org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:324)     at
    org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      at
    org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)  at
    org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)  at
    org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)  at
    org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      at
    org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)</p>
  </blockquote>
  
  <p>This is my Spring controller:</p>
  
  <pre><code>@SuppressWarnings("unchecked")
          @RequestMapping(method=RequestMethod.GET)
            public String listUsers(Map&lt;String, Object&gt; map) {
  
              map.put("user", new User());
              map.put("usersList", usersService.getAllObjects(User.class));
              map.put("groupsList", usersService.getAllObjects(Group.class));
              return "index";
          }
  </code></pre>
  
  <p>This is my JSP page:</p>
  
  <pre><code>&lt;tr&gt;
                    &lt;td&gt;groups&lt;/td&gt;
                    &lt;td&gt;&lt;form:select path="selectedGroup"&gt;
                    &lt;form:options items="${groupsList}"/&gt; 
                    &lt;/form:select&gt;&lt;/td&gt;
                    &lt;/tr&gt;
  </code></pre>
  
  <p>I am new to this. Can anybody help?</p>