-
1. Re: Partially updating an entity
ssamayoagt Feb 13, 2010 3:50 PM (in response to rnicholson10)AFAIK JPA has no way to known which fields were modified, it knows only that the entity instance must be updated.
The only way I see now is refreshing the instance, compare values, set those which changed then apply the changes in the recently retrieved instance.
Also check your application for changes in the entity because one thing is for sure: flush only updates database if some of the setXXXX methods were called even if with the same value.
Regards.
-
2. Re: Partially updating an entity
damianharvey.damianharvey.gmail.com Feb 14, 2010 10:49 AM (in response to rnicholson10)Read up on the @Version annotation for Hibernate. You may be able to artifically increase the version from the C application. Big question marks here so worth checking out. This would only allow your app to generate an OptimisticLockException (or something like that).
AFAIK you can't partially update an entity out-of-the-box but you could store the entity in another object, then refresh the entity from the database (entityManager.refresh()) then compare the values and only update what you want. Messy & fussy but would work. I do similar to generate version history for entity changes (eg.
User X did this
)Cheers,
Damian.
-
3. Re: Partially updating an entity
thokuest Feb 15, 2010 6:26 PM (in response to rnicholson10)
what would be the best way get the entity to only update the fields that had changed instead of updating the entire entity?Using Hibernate, you could try using dynamic-update (Mapping Reference).