Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Avoiding data related code spilling out into the service layer

$
0
0
Hi,

I'm trying to have all data related code reside in the repository layer and not spill out into the service layer.

I have a service method using only primitive types:
Code:

public List<Admin> search(String searchTerm, int pageIndex, int pageSize) {
    return adminRepository.search(searchTerm, pageIndex, pageSize);
}

And a repository method routing it to a standard Jpa method:
Code:

public List<Admin> search(String searchTerm, int pageIndex, int pageSize) {
    Pageable pageSpec = buildPageSpecification(pageIndex, pageSize);
    Page wanted = search(searchTerm, pageSpec);
    return wanted.getContent();
}

With the following method in the repository interface:
Code:

@Query("SELECT a FROM Admin a WHERE LOWER(a.firstname) LIKE LOWER(:searchTerm) OR LOWER(a.lastname) LIKE LOWER(:searchTerm) ORDER BY a.lastname ASC, a.firstname ASC")
public List search(@Param("searchTerm") String searchTerm, Pageable page);

But the service method sees the repository interface method instead of the repository implementation one.

Viewing all articles
Browse latest Browse all 297

Trending Articles