1

I have a need for a repository that simply persists records to the databases, so i wrote a custom generic base repository that extends CrudRepository but only implements the save method, as described here.

@NoRepositoryBean
public interface PersistingRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
   T save(T item);
}

However, my compiler complains that "save(T) in 'PersistingRepository' clashes with 'save(S)' in 'org.springframework.data.repository.CrudRepository'; both method have the same erasure, yet neither overrides the other"

Researching the problem led me to these SO posts: this and this, which place the blame on dependency issues between spring-data-commons and spring-data-jpa. Updating my spring-boot-starter-parent version to 1.5.7.RELEASE results in those dependencies being updated to the most recent RELEASE available on MavenCentral (commons: 1.13.7, jpa: 1.11.7), but the erasure class persists.

So my question is how can this dependency conflict be resolved?

The Head Rush
  • 3,157
  • 2
  • 25
  • 45

1 Answers1

1

Instead of extending CrudRepostory extend its base interface Repository and just define the methods you want to expose. Make sure it matches the signature of methods defined in CrudRepository

Spring documentation defines how to do it in the below link. Look for the section 1.2.1 Defining repository interfaces

https://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html

Jiss Janardhanan
  • 188
  • 2
  • 10