-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Tue Jan 12, 2016 3:06 pm 
Newbie

Joined: Tue Jan 12, 2016 2:56 pm
Posts: 3
Hi All,
We have application work with spring 4 and hibernate 5 just fine, recently we upgrade it to hibernate5.1 we start get error about the native query parameters, one of the example of the query have the issue is the following

Code:
public List<Edi204DrayPortal> findbyHasDrayPortalStatusLimit(DataTablesReqRto criterias) {
      try{
      int start  = criterias.getStart();
      int length = criterias.getLength();
      // Global search string
      String searchValue = criterias.getSearch().getValue();
      List<Order> orderValues = criterias.getOrder();
      List<Columns> colIds = criterias.getColumns();
      
      Query query =   em.createNativeQuery(
         "   select user, apptment, dnum, ln, vendorid, city, coalesce(d.destin, '--ERR PHONE IT--') as rt "
         + ", ramp "
          + ", if(rail is NULL ,'N', 'Y') as rail "
         + ", portalstatus "
         + ", st "
         + ", sentvia "
         + ", coalesce(d.state, '--ERR PHONE IT--') as rtstate "
         + " from ( "
         + " select if(e.dnum = 1, 'Pickup', 'Delivery') as dnum "
            + " ,      e.ln, e.user, e.vendorid, e.portalstatus "
         + " ,      if(e.dnum = 1, date_format(a.apptment,'%Y-%m-%d %H:%i'), date_format(ad.cnapptment,'%Y-%m-%d %H:%i')) as apptment "
         + " ,      if(e.dnum = 1, a.shipst, a.constt) as st "
         + " ,      if(e.dnum = 1, a.shipcity, a.concity) as city "
         + " ,      if(e.dnum = 1, ad.orig1rp, ad.dest1rp) as ramp "
         + " ,      coalesce(rb1.sentvia, '--NONE--') as sentvia "
         + " ,       rb1.rail "
         + " ,      ad.cnunicomp, ad.cnunitel "
         + "   from edi204dray e "
         + " join armast a on a.ln = e.ln "
         + " join additional ad on ad.ln = e.ln "
         + " left join edirailbill rb1 on rb1.ln = e.ln and rb1.recno = (select max(rb2.recno) from edirailbill rb2 where rb2.ln = rb1.ln) "
         + " where e.recno = (select max(ee.recno) from edi204dray ee where ee.ln = e.ln and ee.dnum = e.dnum) "
         + appendSearch(colIds, searchValue)
         + " and portalstatus is not null "
         + " and not ((portalstatus = 'Ingate' or portalstatus = 'Ingate Empty/Street Turn') and DATEDIFF( NOW(), ackdate) > 1) "
         + " order by "
         + appendOrder(orderValues, colIds)         
         + " limit (?1),(?2) "
         + " ) t "
         + " left join dest d on substring(d.destin,1,25) = t.cnunicomp and d.phone = t.cnunitel "
         , "CSRDashBoardMapping");
      
      
       
         return query.setParameter(1, start)
         .setParameter(2, length)
         .getResultList();
      }catch(Exception exp){
         exp.printStackTrace();
      }
      
      return null ;
   }

we inject the em as follow
@PersistenceContext(unitName="mysqlDrayPersistenceUnit")
protected EntityManager em;

this code was working fine in hibernate v5 until we upgrade we start get the following exception I try ?, ?1, and (?1) to add the parameter to the query non of them work on hibernate 5.1, any help from you will be highly appreciated.

11:47:41,593 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/dray-1.0.0-SNAPSHOT].[com.celticintl.dray]] (http-/127.0.0.1:8080-5) JBWEB000236: Servlet.service() for servlet com.celticintl.dray threw exception: java.lang.IllegalArgumentException: Parameter with that position [1] did not exist
at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:501) [hibernate-entitymanager-5.1.0-20160111.170655-128.jar:5.1.0.SNAPSHOT]
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:691) [hibernate-entitymanager-5.1.0-20160111.170655-128.jar:5.1.0.SNAPSHOT]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:181) [hibernate-entitymanager-5.1.0-20160111.170655-128.jar:5.1.0.SNAPSHOT]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:32) [hibernate-entitymanager-5.1.0-20160111.170655-128.jar:5.1.0.SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:360) [spring-orm-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at com.sun.proxy.$Proxy177.setParameter(Unknown Source)
at com.celticintl.dray.dto.Edi204DrayPortal.findbyHasDrayPortalStatusLimit(Edi204DrayPortal.java:224) [classes:]
at com.celticintl.dray.controller.OrderMonitorDashBoardControllerRest.getDataTableInfo(OrderMonitorDashBoardControllerRest.java:34) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) [spring-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at com.celticintl.dray.filters.TenantIdentifierFilter.doFilter(TenantIdentifierFilter.java:80) [classes:]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:208) [cors-filter-2.4.jar:2.4]
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:274) [cors-filter-2.4.jar:2.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.4.8.Final-redhat-4.jar:7.4.8.Final-redhat-4]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Tue Jan 12, 2016 11:39 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Looks like a regression. I think you should open a JIRA issue for it.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Wed Jan 13, 2016 3:55 pm 
Newbie

Joined: Tue Jan 12, 2016 2:56 pm
Posts: 3
The issue was with the -- character in the query which make the query parser not able to find the parameter if we remove the -- from all the query text this query will work fine. the following is test case of what I mean

Code:
   @Test
   @SkipForDialects(
         value = {
               @SkipForDialect(value = Oracle8iDialect.class, jiraKey = "HHH-10161", comment = "Cannot convert untyped null (assumed to be BINARY type) to NUMBER"),
               @SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint"),
               @SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
         }
   )
   public void testNativeQueryWithSpecialChar() throws Exception {
      EntityManager em = getOrCreateEntityManager();
      em.getTransaction().begin();
      Item item = new Item( "Mouse", "Micro$oft mouse" );
      em.persist( item );
      // native queries don't seem to flush by default ?!?
      em.flush();
      Query q = em.createNativeQuery( "select coalesce(i.name, '--NONE--') as itname  from Item i where i.intVal=? " );
      q.setParameter( 1, 1 );
      List results = q.getResultList();
      // null != null
      assertEquals( 0, results.size() );
      em.getTransaction().rollback();
      em.close();
   }


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Thu Jan 14, 2016 3:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It must be a bug, but it requires a JIRA issue to be fixed. Post the link to this issue here after you added it.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Thu Jan 14, 2016 3:56 pm 
Newbie

Joined: Tue Jan 12, 2016 2:56 pm
Posts: 3
I already add JIRA bug ticket


Top
 Profile  
 
 Post subject: Re: Hibernate 5.1 not able to find native query parameter by ind
PostPosted: Thu Jan 14, 2016 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.