How can i add "where" to my request to db from java in JPQL?

57 views Asked by At

How can i add "where" to my request to db from java in JPQL?

I have in service class call method from JpaRepository interface:

List t1List = T1Repository.findById(id) // this is not a PK

id - field from REST API request

And JpaRepository interface looks like:

public interface T1Repository extends JpaRepository<T1, Long> {

    @Query("select m from T1 m LEFT JOIN FETCH m.T2 where m.id= :id")
    List<T1> findById(@Param("id") String id);
}

If i remove "where m.id= :id" it will response with all rows from all tabs, but with "where m.id= :id" - it response nothing

Help please

above all that try to use

1

There are 1 answers

1
Pabs On

Try changing where m.id= :id

with this: where m.id= ?1