tags:

views:

56

answers:

1

I have an Entity User that is assigned a system privilege in a function. I have a web page where you select a user from a drop down and submit the form to the server. On the server side I want to update only one field for that entity.

My User Entity will have default values for all objects except the one field that gets set and its id. Do I need to do a findById then update the specific field then do the merge or is there a way to tell the to only update that field?

+1  A: 

Do I need to do a findById then update the specific field then do the merge

That would be the regular approach, except that you don't need to merge a managed entity, just let JPA detect the changes and update it automatically.

or is there a way to tell the to only update that field?

No. But you could use a "short" version of your User (with only the field(s) to update). Another option would be to use a Bulk Update Operation but this is IMO really not a good use case. I wouldn't use this approach.

Reference

  • JPA 1.0 specification
    • 4.10 Bulk Update and Delete Operations
Pascal Thivent
@Pascal , what do you mean by Short version of User?
geoaxis