0

I need to implement filtering to all entities' repositories.

The filtering follows the same scenario, differing only in Filter and Entity params.

So now I have my filter interface:

interface RepositoryFilter<Entity, Filter> {
 fun findAllByFilter(filter: Filter, pageable: Pageable): PageImpl<Entity>
}

An abstract class which implements several methods used in findAllByFilter implementation:

abstract class AbstractRepositoryFilter<Entity, Filter>(
 private val jdbcTemplate: NamedParameterJdbcTemplate
) : RepositoryFilter<Entity, Filter> {
 override fun findAllByFilter(filter: Filter, pageable: Pageable): RestResponsePage<Entity> {
 val sql = initSqlQuery() // to be implemented in concrete class
 val params = mutableMapOf<String, Any>() 
 appendFilterParams(filter, sql, params) // to be implemented in concrete class
 val total = countFiltered(sql, params) // is implemented in AbstractRepositoryFilter
 val result = collectFiltered(sql, params) // to be implemented in concrete class
 return RestResponsePage(result, pageable, total)
 }
}

A concrete class, that implements functionality for concrete Entity (Event):

class RepositoryFilterImpl(
 jdbcTemplate: NamedParameterJdbcTemplate
) : AbstractRepositoryFilter<Event, EventFilter>(jdbcTemplate) {
 override fun initSqlQuery(): StringBuilder {
 // implemention 
 }
 override fun appendFilterParams(filter: EventFilter, sql: StringBuilder, params: MutableMap<String, Any>) {
 // implemention 
 }
 override fun collectFiltered(sql: StringBuilder, params: MutableMap<String, Any>): List<Event>
 {
 // implemention 
 }
}

The result repository:

@Repository
interface EventRepository : CrudRepository<Event, Long>, RepositoryFilter<Event, EventFilter>

However, I get the same mistake, trying to compile this:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property 'filter' found for type 'Event'
 at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-3.4.2.jar:3.4.2]
 at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:455) ~[spring-data-commons-3.4.2.jar:3.4.2]

I want to avoid boilerplate code, that's why I tried to use an abstract class...

Georgii Lvov
3,7831 gold badge8 silver badges35 bronze badges
asked Apr 9 at 12:36
1
  • I was trying to follow an example provided in Spring's Custom Repository Implementations. There is a UserRepository (my EventRepository), which extends CustomizedSave interface (my RepositoryFilter). In turn, CustomizedSave is implemented by CustomizedSaveImpl (my RepositoryFilterImpl as i hope) Commented Apr 9 at 20:27

1 Answer 1

0

I think you should check , you annotate "@EnableJpaRepositories" at configuration.

answered Apr 14 at 9:04
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.