Results 1 to 6 of 6

Thread: @Query & Spring Expression Language

  1. #1

    Default @Query & Spring Expression Language

    Hi All,

    I have a repository that extends JpaRepository. I have a custom query that depends on the value of an enumeration. I would prefer not to hard code the enumeration into the query and have Spring pick it up automatically. How can I accomplish something like this:


    Code:
    	// Gets this user's finished jobs
    	@Query("select j from SyncJob j where j.ownerId = ?1 and status = " + Status.FINISHED)
    	public SyncJob findFinishedJobs(long ownerId);
    Thanks!
    Doug

  2. #2
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

    Default

    Yes, you can:

    Code:
    	@Query("select c from Customer c where c.status = org.springframework.data.jpa.showcase.core.Status.FINISHED")
    	List<Customer> findByEnum();

  3. #3

    Default

    That worked! Thanks!

  4. #4

    Default

    Hi,

    I read your great post on spring Data pagination but I still have this problem:



    3:55:07,308 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/QL].[Spring MVC Dispatcher Servlet]] (http--127.0.0.1-8080-1) Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.data.domain.Pageable]: Specified class is an interface
    at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:101) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.method.annotation.ModelAtt ributeMethodProcessor.createAttribute(ModelAttribu teMethodProcessor.java:131) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotat ion.ServletModelAttributeMethodProcessor.createAtt ribute(ServletModelAttributeMethodProcessor.java:8 1) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.method.annotation.ModelAtt ributeMethodProcessor.resolveArgument(ModelAttribu teMethodProcessor.java:102) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]


    Ive tried your @EnableWebMvc, Ive also tried extending WebMvcConfigurationSupport (without @EnableWebMvc) and Ive also tried pure xml like this:

    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <bean class="org.springframework.http.converter.json.Map pingJacksonHttpMessageConverter"/>
    </list>
    </property>
    <property name="customArgumentResolvers">
    <list>
    <bean class="org.springframework.data.web.PageableArgume ntResolver" />
    </list>
    </property>
    </bean>


    but still getting this same error in all cases, any idea whats going on here ?

  5. #5

    Default

    Hi Emmett,

    Thanks for reading my post! Try posting this in a new thread so other people will see it too and can you help you out. Can you also post your controller method?

    Thanks!
    Doug

  6. #6

    Default

    Hi,

    yes i eventually solved it after many hours... <mvc:annotation> was the root cause

    http://forum.springsource.org/showth...Web-pagination

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •