I\'m considering spring data for a project. Is it possible to override the per default generated save method? And if yes, how?
What works for me (Spring boot 2.x Java 11), even if not perfectly clean. It compiles with IDE and Maven and Gradle. The above solution by Lucas does not work for me for the JpaRepository.
public interface MyRepo extends JpaRepository, MyRepoCustom{
//Implemented in MyRepoCustom
public MyType save(MyType mytypeEntity);
}
The custom interface (repeats the declaration, which is not nice):
public interface MyRepoCustom{
public MyType save(MyType mytypeEntity);
}
The custom Impl:
@Repository
public class MyRepoImpl implements MyRepoCustom{
@PersistenceContext
private EntityManager em;
@Transactional
public MyType save(MyType mytypeEntity) {
//type safe implementation
}
}