Let's suppose to have this situation:
We have Spring Data configured in the standard way, there is a Respository
object, an Entity
object and all works well.
Now for some complex motivations I have to use EntityManager
(or JdbcTemplate
, whatever is at a lower level than Spring Data) directly to update the table associated to my Entity
, with a native SQL query. So, I'm not using Entity
object, but simply doing a database update manually on the table I use as entity (it's more correct to say the table from which I get values, see next rows).
The reason is that I had to bind my spring-data Entity
to a MySQL view that makes UNION of multiple tables, not directly to the table I need to update.
What happens is:
In a functional test, I call the "manual" update method (on table from which the MySQL view is created) as previously described (through entity-manager) and if I make a simple Respository.findOne(objectId)
, I get the old object (not updated one). I have to call Entitymanager.refresh(object)
to get the updated object.
Why?
Is there a way to "synchronize" (out of the box) objects (or force some refresh) in spring-data? Or am I asking for a miracle? I'm not ironical, but maybe I'm not so expert, maybe (or probably) is my ignorance. If so please explain me why and (if you want) share some advanced knowledge about this amazing framework.