for example: 1.I have 100 entities in a database 2.when i select all those 100 entities via select query,will those entities be loaded to managed context? 3.If yes , what happens if we dont change any attribute values of those entities,will it be committed again to the database after flush method gets called?
Asked
Active
Viewed 20 times
0
-
1(2) yes (3) if no changes have been made, most (if not all) JPA implementations will not issue any updates to the DB – crizzis Sep 20 '20 at 11:52
-
would not the loaded entities needs to be stored back to database even if their attributes are not changed? – kumar rishav Sep 20 '20 at 12:40
-
sorry i might be asking basic question , but i am new to entity manager concept. – kumar rishav Sep 20 '20 at 12:41
-
Why would you think they need to be stored? JPA implementations either keep track of any change you make to an entity, or 'remember' the original state the entity was in right after being loaded into the context. If no changes are detected at persist time, no updates are issued to the DB – crizzis Sep 20 '20 at 12:57