-->
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.  [ 3 posts ] 
Author Message
 Post subject: Paramters not always found in NativeQuery
PostPosted: Fri Jun 01, 2007 6:07 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hibernate version: 3.2.0GA

Mapping documents: None, annotations being used

Full stack trace of any exception that occurs:
Code:
Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [y]
        at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
        at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
        at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
        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:78)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
        at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
        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:181)
        at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
        at $Proxy175.testQueryData(Unknown Source)
        at com.test.spatial.mbean.GeoDataTester.queryData(GeoDataTester.java:41)
        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:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        ... 29 more
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [y]
        at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:177)
        at com.test.spatial.beans.GeoTestBean.queryGeoItems(GeoTestBean.java:68)
        at com.test.spatial.beans.GeoTestBean.testQueryData(GeoTestBean.java:52)
        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:585)
        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)
        ... 50 more
Caused by: org.hibernate.QueryParameterException: could not locate named parameter [y]
        at org.hibernate.engine.query.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:75)
        at org.hibernate.engine.query.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:81)
        at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:413)
        at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:383)
        at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:172)
        ... 65 more


Name and version of the database you are using: Postgresql 8.1.4

Hi, i am using PostGis in conjunction with Postgres in an EJB3 environment (using a User defined Type). The persisting works fine, the querying via a native query works fine so long as it is a query string with no parameters. The problems start to occur when adding some parameters to the query, but it only happens when parameters are added in a certain places in the query string.

The following query works:

Code:
      // create the native query
      Query nativeQuery = mEntityManager.createNativeQuery("SELECT * FROM table " +
            "WHERE the_geom && Expand(GeomFromText('POINT(5 5)', -1), :distance) " +
            "AND Distance(GeomFromText('POINT(5 5 )', -1), the_geom) < :distance", geoItem.class);
      
      // set the parameters
      nativeQuery.setParameter("distance", pDistance);


But the following one causes the stack trace above

Code:
      // create the native query
      Query nativeQuery = mEntityManager.createNativeQuery("SELECT * FROM table " +
            "WHERE the_geom && Expand(GeomFromText('POINT(5 5)', -1), :distance) " +
            "AND Distance(GeomFromText('POINT(5 :y )', -1), the_geom) < :distance", geoItem.class);
      
      // set the parameters
      nativeQuery.setParameter("distance", pDistance);
      nativeQuery.setParameter("y", pPointY);


It appears to me that any parameter placed between the brackets of the POINT definition are never found !! But the distance paramter is found !!

In my opinion this is a bug. Should i enter a JIRA issue for it (it will take me a while to reduce it to a runnable test case)?

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 9:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's in quote, Hibernate must not replace things in quote.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 9:15 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Thanks Emmanuel, i did not spot that. I now just escape the string and insert the value

_________________
Rules are only there to be broken


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.