You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
@ConfigurationpublicclassEmployeeCallbacks {
@BeanpublicAfterConvertCallback<Employee> afterConvert() {
return (employee, table) -> {
// Do something with the entity
};
}
}
publicinterfaceEmployeeRepositoryextendsReactiveCrudRepository<Employee, Long> {
@Query("SELECT * FROM employee WHERE name=:name")
Mono<Employee> findFirstByName(Stringname); // This never triggers the callback ❌Mono<Employee> findFirstByLastname(Stringlastname); // 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!
The text was updated successfully, but these errors were encountered:
The difference in behavior comes from the differences in running the SQL statement. SimpleR2dbcRepository uses R2dbcEntityOperations which makes use of entity callbacks while query methods directly use DatabaseClient. We need to migrate query method execution into R2dbcEntityOperations so we can reuse entity callbacks.
Awesome, thank you @mp911de! Entity callbacks are extremely helpful. I use them to eagerly populate relational fields (one to one, one to many, etc.), which need to be transient in the model for the time being.
Just for me to be on the lookout, it's possible to know in which version of Spring Boot will this be available?
The next Boot generation that will pick up these changes is going to be Spring Boot 2.6. There's new API and quite a bit of rewrite required to make this work and that bears a certain risk.
Hi,
I'm trying to use entity callbacks like
AfterConvertCallback
orBeforeConvertCallback
in my project, which work great for built-in query methods like.findAll()
orfindById(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
Code sample
As always, thanks for the great work on this project.
Cheers!
The text was updated successfully, but these errors were encountered: