I have a hibernate entity called Execution. It is created in the beginning of my process and updated at end, indicating how it has finished.
I would like to update a single property of this entity, without causing a select in my database.
Execution execution = entityManager.getReference(Execution.class, executionId);
execution.setStatus(Status.FINISHED);
//--> Calling this method fires a SELECT in my Database. I didn't want it to happen, I just want to update my entity.
This is not specific to this method, any other method called results in a SELECT clause. In fact, the select appears to happen even before my method is called. My impression is that hibernate proxies put some code inside my class no-args contructor to fire a select everytime any method is called.
Is it possible to update JPA/Hibernate entities without firing a SELECT statement in my database?
This is how Hibernate works. Its proxy object loads the real object from DB whenever any non-id property is accessed.
Try saving/loading the object at the beginning of your process (to execute that SELECT
), and make sure that the session does not auto-flush whenever an object is touched (I think the default behaviour is no auto-flush, but it is worth a check).
Or you could also try detaching your object from the Hibernate session during processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With