Updating a JPA-Hibernate Object Without Selecting It from the Database

I have a hibernation object called Execution. It is created at the beginning of my process and updated at the end, indicating how it ended.

I would like to update one property of this object without causing a selection in my database.

Execution execution = entityManager.getReference(Execution.class, executionId); execution.setStatus(Status.FINISHED);// -> Calling this method calls SELECT in my database. I did not want this to happen, I just want to update my essence.

This does not apply to this method, any other method called results in the SELECT clause. In fact, a choice appears, happens even before my method is called. My impression is that hibernate proxies put some code inside my no-args contructor class to run the selection every time any method is called.

Is it possible to update JPA / Hibernate objects without running SELECT statements in my database?

+5
source share
1 answer

This is how Hibernate works. Its proxy object loads the real object from the database whenever it is accessed by any properties other than id.

Try saving / loading the object at the beginning of your process (to do this SELECT) and make sure that the session does not disconnect automatically every time you touch the object (I think that the default behavior is not automatic, flash, but worth checking).

Or you can also try disconnecting your object from the Hibernate session during processing.

+1
source

All Articles