2 Replies Latest reply on Dec 11, 2007 6:06 AM by Daniel Kane

    native query and

    Daniel Kane Novice

      Dear colleagues,

      The following code :

      Integer count = (Integer)
       em.createNativeQuery("SELECT count(*) as cnt FROM Users_Terminals ut where "+"tId=" + termId + " and uId=" +userId).getSingleResult();
      


      throws the following exception ,
      although another native query with single result (but without aggregate function) in neighbouring method works well.

      2007-12-11 11:32:38,929 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [SELECT count(*) FROM Users_Terminals WHERE (Users_Terminals.tId=123 ) and (Users_Terminals.uId=1)]
      java.sql.SQLException: Column '' not found.
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
       at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:961)
       at com.mysql.jdbc.ResultSet.getBigDecimal(ResultSet.java:1226)
       at org.jboss.resource.adapter.jdbc.WrappedResultSet.getBigDecimal(WrappedResultSet.java:312)
       at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
       at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
       at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
       at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
       at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
       at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
       at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
       at org.hibernate.loader.Loader.doQuery(Loader.java:701)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
       at org.hibernate.loader.Loader.doList(Loader.java:2220)
       at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
       at org.hibernate.loader.Loader.list(Loader.java:2099)
       at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
       at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
       at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
       at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
       at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
       at track.reports.TraceReporterBean.isUserTerm(TraceReporterBean.java:40)
       at track.reports.TraceReporterBean.dailyTraceReport(TraceReporterBean.java:56)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:174)
       at org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3.invokeServiceEndpointInstance(ServiceEndpointInvokerEJB3.java:114)
       at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:207)
       at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212)
       at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448)
       at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
       at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:619)
      


      Please help to solve that. Thank you.

        • 1. Re: native query and
          Arne Luedtke Newbie

          Hy,

          I had some Problems with count(*) in the past. Try to use count(IDColumn) or another not null column.

          Greetings Soon5

          • 2. Re: native query and
            Daniel Kane Novice

             

            "Soon5" wrote:
            Hy,

            I had some Problems with count(*) in the past. Try to use count(IDColumn) or another not null column.

            Greetings Soon5



            Thank you for the idea.

            Got a workaround by replacing count(*) with :

            List l = (List)
             em.createNativeQuery("SELECT uId FROM Users_Terminals ut where "+
             "tId=" + termId + " and uId=" +userId).getResultList();
             return(l!=null && l.size()>0 && ((Integer)(l.get(0))).intValue()>0);
            


            But still interesting ..