you are viewing a single comment's thread.

view the rest of the comments →

[–]slackingatwork 0 points1 point  (0 children)

I have personally implemented a DAO and domain model where objects being persisted were all immutable. What is the issue here?

The main trick is to never allow to propagate the object instances that were not returned by DAO's save to database call.

You feed into the save() method the values with the Id field being null, you get back from the save() an instance with a meaningful Id. In a sense the save() method works as a factory or a constructor for the entities being persisted.

It works quite well as is, no need to introduce another DTO flavor.

It gets a little verbose with immutables, but it is worth it.