can not use spring-data-jpa repository with NamedQuery

#1

in spring-data-jpa named queries are used to implement repository interface methods, see

http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/#jpa.query-methods.named-queries

for example

@NamedQuery(name = "Foo.findByBar", query = "select f from Foo f where :bar member of f.bars")
public class Foo implements Persistable<Long> {
    private Set<String> bars;

will be used to implement

public interface FooRepository extends JpaRepository<Foo, Long> {
    Foo findByBar(String bar);
}

to match the method parameter to the query parameter, spring have to check the query for named parameters

    public static boolean hasNamedParameter(Query query) {

        for (Parameter<?> parameter : query.getParameters()) {
            if (parameter.getName() != null) {
                return true;
            }
        }

        return false;
    }

 

but getParameters throws UnsupportedOperationException

 

java.lang.UnsupportedOperationException: Unsupported feature - Typed Parameters are not supported yet
at com.objectdb.o.JPE.g(JPE.java:121)
at com.objectdb.o.ERR.f(ERR.java:59)
at com.objectdb.o.OBC.onObjectDBError(OBC.java:1416)
at com.objectdb.o.OST.F(OST.java:597)
at com.objectdb.jpa.JpaQuery.getParameters(JpaQuery.java:555)
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.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310)
at $Proxy24.getParameters(Unknown Source)
at org.springframework.data.jpa.repository.query.QueryUtils.hasNamedParameter(QueryUtils.java:266)
at org.springframework.data.jpa.repository.query.ParameterBinder.hasNamedParameter(ParameterBinder.java:163)
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:119)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:187)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:57)
at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doExecute(AbstractStringBasedJpaQuery.java:54)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:99)
at org.springframework.data.repository.support.RepositoryFactorySupport$QueryExecuterMethodInterceptor.invoke(RepositoryFactorySupport.java:304)

 

do you think this can be fixed?

thanks in advanced

#2

Implementation of the getParameters method was just added in build 2.2.3_02. Please try it.

ObjectDB Support
#3

works perfectly,

thanks again for this quick response

Reply