I have a Java Spring project with JPA persistence using EclipseLink. I want to use JpaRepository interfaces for my entities and the default implementations for most cases but I also need to define a few of my own methods and I need to sometimes override the default methods like save.
My code works when compiled in Eclipse, but I keep getting an ambiguous reference error when compiling with Maven.
What I have done is this (for example to override save because I need to do certain things to the entity to be saved):
public interface ReportRepository extends JpaRepository<Report, Long>, ReportRepositoryCustom {
}
public interface ReportRepositoryCustom {
public Report save(Report report);
public int getReportCountForImporter(Long importerId);
...
}
public class ReportRepositoryCustomImplementation implements ReportRepositoryCustom {
public Report save(Report report) { ... }
public int getReportCountForImporter(Long importerId) { ... }
}
public class ReportService {
@Autowired
private ReportRepository reportRepository;
}
This works fine in Eclipse when I compile it to run on Tomcat. The object ReportRepository reportRepository has methods from JPA repository implementation and my custom methods and the custom save method is called when I call reportRepository.save(...). However, when I do Maven Install, the compiler complains about an ambiguous reference:
[ERROR] /C:/Users/Jarno/git/Korjaamotestiraportointi/src/main/java/fi/testcenter/service/ReportService.java:[40,40] reference to save is ambiguous both method save(fi.testcenter.domain.report.Report) in fi.testcenter.repository.ReportRepositoryCustom and method save(S) in org.springframework.data.repository.CrudRepository match
I've found coding my repositories a bit complicated. I would like to use the ready-made implementations for JPA repositories and not have to code anything extra. My code keeps everything nice and clean. The repository interface to be used as reference in services is named the same way for every entity and methods are also named the same and any custom methods or overrides are done through custom interfaces and implementations. I don't need to write any unnecessary code anywhere. But then I ran into my problem with Maven.
I have managed to compile my code with Maven by first running it in Eclipse Tomcat server. But if I do Maven Clean and then Maven Install, I get a bunch of errors. And obviously I'd like to not have to resort to any kind of a hack in compiling with Maven.
So is there a fix that would allow to do this with Maven? Or is there another way of coding what I want to do here?