0

I am calling findall() method of the JpaRepository as following

Service

on.findall(specificationsbuilder.getspecifications(params), paegable obj)  

specificationsbuilder.getspecifications(param)

returns specifications

My question is if specifications is null will my will findall(specifications,paegable) work

Alien
  • 15,141
  • 6
  • 37
  • 57
Sarthak
  • 188
  • 1
  • 2
  • 14

2 Answers2

3

According to the sourcecode of SimpleJpaRepository it should work, because @Nullable says it will accept null:

@Override
    public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable) {

        TypedQuery<T> query = getQuery(spec, pageable);
        return isUnpaged(pageable) ? new PageImpl<T>(query.getResultList())
                : readPage(query, getDomainClass(), pageable, spec);
}
Robert Niestroj
  • 15,299
  • 14
  • 76
  • 119
1

read here : https://jira.spring.io/browse/DATAJPA-121, as of latest spring data jpa, the query will automatically form is null if your parameter is null.

Also, Since Spring data jpa 2.0, spring now supports @Nullable annotation. This can be helpful to handle null parameters passed.

@Nullable – to be used on a parameter or return value that can be null.

if the value is null it will automatically return true and if is not null, it will search that value in the table.

Samyak Jain
  • 95
  • 1
  • 3