1

I want to inject a Spring-Bean into every Entity returned by a repository implemented with Spring-Data (using JPA / Hibernate).

What is the best way to do this?

I have found two options:

  1. write a wrapper for the Spring Data repositories. This is cumbersome because it would mean overwriting lots of methods.

  2. write an JPA CallbackListener. I'd rather not depend on JPA/Hibernate and prefere something based on Spring, since it would allow me to use the same approach for Entities not created by JPA/Hibernate

Is there a way to do this purely based on Spring(Data) without drowning in boilerplate code for overwriting dozens of methods?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

0 Answers0