I am doing some CRUD operations using JPA. For updating an object which is the right way to do?
Through update query or through the find
method of EntityManager
?
I have one Employee
object I need to update. Which is the right way?
Please guide me.
This question is related to
java
jpa
entitymanager
That depends on what you want to do, but as you said, getting an entity reference using find()
and then just updating that entity is the easiest way to do that.
I'd not bother about performance differences of the various methods unless you have strong indications that this really matters.
It depends on number of entities which are going to be updated, if you have large number of entities using JPA Query Update statement is better as you dont have to load all the entities from database, if you are going to update just one entity then using find and update is fine.
Source: Stackoverflow.com