veer
veer

Reputation: 127

how to write not in clause using springboot findAll() method

I am try to get data from the database using spring boot JPA and CRUD Repository findAll() method with using not in clause but not find any where. There is any solution making dynamic query using findAll() method.

Example:

hql="select * from urlMaster urlmast where urlmast.urlcd not in (select distinct acturl.acuCd from ActionUrl acturl) order by urlmast.urlcd";

Currently I am just getting data from the urlMaster data. But i want acturl.acuCd not in ActionUrl table.

Repository class:

public interface ActionUrlRepository extends CrudRepository<urlMaster, Long>,JpaRepository<urlMaster, Long> {

}

Service implementation:

actionurlrepository.findAll();

If there is any provision? Please guide me. Thanks!

Upvotes: 0

Views: 1289

Answers (1)

racraman
racraman

Reputation: 5034

You could put your query string in an @Query annotation, as described in https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query

So something like :

public interface ActionUrlRepository extends JpaRepository<urlMaster, Long> {

    @Query("select * from urlMaster urlmast where urlmast.urlcd not in (select distinct acturl.acuCd from ActionUrl acturl) order by urlmast.urlcd")
    List<urlMaster> findByNotIn();
}

By the way, you don't need CrudRepository on the declaration, since JpaRepository already extends from it (via PagingAndSortingRepository).

Upvotes: 1

Related Questions