Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no parameter binding found for name (Spring data jpa)

I have two entities like A and B such that:

 class B {
    private Integer id;
    private String field1;
    private String field2;
    // getters and setters   
 }

 class A {
    private Date date;
    //one to one mapping is there between A and B
    private B b;
    //getters and setters
 }

I have a spring data repository such that:

 @Query("from A a where a.date= :date and a.b.id =:#{#b.id}")
        A findByBAndDate(@Param(value = "date") Date date,@Param(value = "b") B b);

But I am getting the exception, no parameter binding found for name b!.

However, if I modify the above query as:

@Query("from A a where a.b.id =:#{#b.id}")
A findByB(@Param(value = "b") B b);

all works fine. What's the issue with this.

like image 322
Kumar-Sandeep Avatar asked Mar 15 '16 07:03

Kumar-Sandeep


1 Answers

It seems that we must use SPeL for all parameters in the query, not mixing jpa ways and SPel : :date mixed with :#{#b.id}.

Try this, I have not tested I don't know how it would behave with a Date :

 @Query("from A a where a.date= :#{#date} and a.b.id =:#{#b.id}")
        A findByBAndDate(@Param(value = "date") Date date,@Param(value = "b") B b);
like image 81
Stephane L Avatar answered Sep 29 '22 17:09

Stephane L