开发者

What is the best way to Update only 1 field of a big Business Object inside a transaction?

I am in a开发者_运维问答 situation where I have to perform a transaction master detail record (Drop prev details, insert new details, Update Master status)

  1. Master Business Object has 20 fields
  2. Details Business Object has 4 fields only

Now I have to update only 1 field in master table and 4 fields in details table for insert.

If I initialize a new master object, 19 fields are being wasted for a simple update. What do I do to efficiently handle this situation ?

Can I make a new object and inherit only one field from my master business object ? Please give me a little working example if you advise me a DTO or something with inheritance. Thanks.


I guess you mean exposing those 4 fields, instead of inheriting them since you cannot really inherit fields, only a class.

You could make a smaller, simpler 'update object', but I would only do so if this smaller object also exists logically in your model. Ideally, you really don't want to create special objects for updating only parts of your business objects. Instead, it's the task of your persistence layer to be smart enough to know which fields have changed and act accordingly (ie only update those fields).

So in summary:

  • Make an update object only if its also a logical part of your Domain Model
  • Trust in your persistence layer to see what has changed.


Create DTO with those 4 fields. UI will send this DTO to business layer which will use new values to modify business object. Than you persist that modified business object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜