5 Replies Latest reply on Feb 15, 2017 2:18 AM by jaikiran pai

    The column name X was not found in this ResultSet.

    Erroll Sipagan Newbie

      So I have this Company entity:

       

      @Entity

      @XmlRootElement

      public class Company {

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          private Long id;

          @Column

          private String name;

          public Long getId() {

              return id;

          }

          public void setId(Long id) {

              this.id = id;

          }

          public String getName() {

              return name;

          }

          public void setName(String name) {

              this.name = name;

          }

      }

       

      This works fine every time I add a company, but when I added a name property to Column Annotation, example:

       

      @Entity

      @XmlRootElement

      public class Company {

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Column(name = "\"Id\"")

          private Long id;

          @Column(name = "\"Name\"")

          private String name;

          public Long getId() {

              return id;

          }

          public void setId(Long id) {

              this.id = id;

          }

          public String getName() {

              return name;

          }

          public void setName(String name) {

              this.name = name;

          }

      }

       

       

      I got this error on server log every time I attempt to add a company :

       

      org.postgresql.util.PSQLException: The column name "Id" was not found in this ResultSet.

       

      Can someone explain what is wrong in my code. Thank you in advance.

       

      Full sever log:

       

      2017-02-09 13:37:40,650 ERROR [io.undertow.request] (default task-15) UT005023: Exception handling request to /test/rest/companies: org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [test.model.Company]

          at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:77)

          at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:220)

          at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:175)

          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:418)

          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)

          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)

          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)

          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

          at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

          at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

          at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

          at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

          at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

          at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

          at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

          at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

          at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

          at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)

          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)

          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

          at java.lang.Thread.run(Thread.java:745)

      Caused by: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [test.model.Company]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:67)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)

          at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)

          at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)

          at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

          at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:198)

          at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:185)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

          at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)

          at org.jboss.tools.examples.rest.CompanyEndpoint$$$view398.create(Unknown Source)

          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:498)

          at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)

          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)

          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)

          ... 43 more

      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [test.model.Company]

          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)

          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)

          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)

          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1152)

          at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:580)

          at org.jboss.tools.examples.rest.CompanyEndpoint.create(CompanyEndpoint.java:37)

          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:498)

          at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)

          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)

          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)

          at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)

          at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)

          at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

          at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)

          ... 87 more

      Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [test.model.Company]

          at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)

          at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)

          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)

          at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:49)

          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2803)

          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3374)

          at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)

          at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:619)

          at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:273)

          at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:254)

          at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:299)

          at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:317)

          at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:272)

          at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:178)

          at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:109)

          at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)

          at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)

          at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)

          at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)

          at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:775)

          at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:748)

          at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:753)

          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1146)

          ... 118 more

      Caused by: org.postgresql.util.PSQLException: The column name "Id" was not found in this ResultSet.

          at org.postgresql.jdbc.PgResultSet.findColumn(PgResultSet.java:2591)

          at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2489)

          at org.jboss.jca.adapters.jdbc.WrappedResultSet.getLong(WrappedResultSet.java:1583)

          at org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:138)

          at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:73)

          at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:61)

          at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)

          ... 137 more

        • 1. Re: The column name X was not found in this ResultSet.
          jaikiran pai Master

          Erroll Sipagan wrote:

           

           

          @Entity

          @XmlRootElement

          public class Company {

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Column(name = "\"Id\"")

          private Long id;

          @Column(name = "\"Name\"")

          private String name;

           

           

          You shouldn't be including the double quote literals in the column name. Change it to:

           

          @Id

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          @Column(name = "Id")

          private Long id;

          @Column(name = "Name")

          private String name;

           


          and that should work

          • 2. Re: The column name X was not found in this ResultSet.
            Erroll Sipagan Newbie

            Thank you for answering but I forgot to mention that I'm using PostgreSQL and I use double quote literals to map the columns of the table in pascalcase, so your answer produces lowercase columns(eg. id, name) not pascalase columns(eg. Id, Name)...

            • 3. Re: The column name X was not found in this ResultSet.
              jaikiran pai Master

              Erroll Sipagan wrote:

               

              I use double quote literals to map the columns of the table in pascalcase, so your answer produces lowercase columns(eg. id, name) not pascalase columns(eg. Id, Name)...

              I don't fully understand. Are you saying that if you don't literally include those double quotes in the @Column annotation value, the column names of your table in Postgres DB get *generated* with all lower case? So does that mean, you are using JPA/Hibernate feature to auto generate the tables for you in the DB via these annotation mappings?

              • 4. Re: The column name X was not found in this ResultSet.
                Erroll Sipagan Newbie

                1.If I don't use those double quotes, table columns are in lower case.

                2.Yes, I use JPA/Hibernate feature to auto generate the tables for me in the DB, is this practice is wrong?

                 

                Sorry, I'm just a beginner that learning JPA/Hibernate by myself so I know little things about it.

                Thanks

                • 5. Re: The column name X was not found in this ResultSet.
                  jaikiran pai Master

                  Erroll Sipagan wrote:

                   

                   

                  2.Yes, I use JPA/Hibernate feature to auto generate the tables for me in the DB, is this practice is wrong?

                   

                  I wouldn't call it wrong, but in real production systems/applications, I have seen recommendations that the DB schema/table generation be handled via explicit scripts instead of via JPA. Personally, I consider the auto creation/updation of DB schema via JPA to be a developer convenience feature than a production one.

                   

                  Erroll Sipagan wrote:

                   

                  1.If I don't use those double quotes, table columns are in lower case.

                  Now, coming to this, I will have to check JPA spec of some Hibernate details to understand if it has some configurable policy which tells it what naming scheme to use in auto generation of table and columns.

                   

                  I would however recommend that if this is an application that you are considering for production, better have more control on the DB schema creation in a separate scripts of your own instead of letting JPA generate the schema.