-
Notifications
You must be signed in to change notification settings - Fork 130
Description
Hi,
I'm trying to use entity callbacks like AfterConvertCallback or BeforeConvertCallback in my project, which work great for built-in query methods like .findAll() or findById(ID id). However, it seems they are not being fired for String-based queries or named query methods.
I might be missing something, but I tracked the issue a little bit, and it seems the entity callbacks are only called from the R2dbcEntityTemplate methods. As far as I could tell, string-based queries and named query methods don't go through these methods (like select(Query query, Class entityClass) or insert(T entity)).
I'd be more than happy to help if someone could point me in the right direction. It seems that this could need some design discussion to probably move the callbacks to a higher level, or maybe just call them from the places where other queries run too. In any case, I'm always happy to contribute if possible. 🙂
Versions
- Spring Boot: v2.4.5
- JVM: Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Code sample
@Configuration
public class EmployeeCallbacks {
@Bean
public AfterConvertCallback<Employee> afterConvert() {
return (employee, table) -> {
// Do something with the entity
};
}
}public interface EmployeeRepository extends ReactiveCrudRepository<Employee, Long> {
@Query("SELECT * FROM employee WHERE name=:name")
Mono<Employee> findFirstByName(String name); // This never triggers the callback ❌
Mono<Employee> findFirstByLastname(String lastname); // This never triggers the callback ❌
// Mono<Employee> findById(Long id); // This is built-in, this always triggers the callback ✅
}As always, thanks for the great work on this project.
Cheers!