Spring data JPA Spel - @Query Issue -
i having trouble getting spel , spring data jpa work
following repository
package eg.repository; public interface myentityrepository extends jparepository<myentity, long>,jpaspecificationexecutor<myentity> { @query("select e eg.domain.myentity e " + "where e.title = :#{#filter.title}" ) page<myentity> list1(@param("filter") myfilter filter,pageable pageable); }
filter component
package eg.service; import org.springframework.stereotype.component; @component("filter") public class myfilter { public string titlefilter() { return "%title%"; } private string title = "title title1"; public long[] idfilter() { return new long[] { 1l, 2l }; } }
following myentity
package eg.domain; @entity public class myentity implements serializable { @id @generatedvalue(strategy = generationtype.identity) private long id; @column(name = "title") private string title; ...... }
main class
log.info("application initialized " + annotationconfigapplicationcontext); myentityrepository myentityrepository = (myentityrepository) annotationconfigapplicationcontext.getbean(myentityrepository.class); myfilter filter = annotationconfigapplicationcontext.getbean(myfilter.class); pagerequest pagerequest = new pagerequest(0, 5); page<myentity> page = myentityrepository.list1(filter,pagerequest); list<myentity> entities= page.getcontent(); for(myentity entity: entities){ system.out.println(entity.getid() + " title " + entity.gettitle()); }
following error getting
exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'myentityrepository': factorybean threw exception on object creation; nested exception java.lang.illegalstateexception: using named parameters method public abstract org.springframework.data.domain.page eg.repository.myentityrepository.list1(eg.service.myfilter,org.springframework.data.domain.pageable) parameter 'filter' not found in annotated query 'select e eg.domain.myentity e e.title = :#{#filter.title}'!
private string title = "title title1";
title of filter private , not see getter property. may problem.