Should DTO include IDENTITY(auto-increment) Id field?

Discussions

EJB design: Should DTO include IDENTITY(auto-increment) Id field?

  1. Should DTO include IDENTITY(auto-increment) Id field? (2 messages)

    Should a DTO that relates to a Customer table in a database include the Id field which is an IDENTITY field in the database, i.e. internally generated value?

    It seems to me that the Id should not be exposed to the client software (such as UI software that recieves instances of the DTO from a Session Facade). On the other hand, if the client software needs to change the values in the DTO and then invoke "mySessionFacade.updateCustomer(CustomerDTO dto)", the updateCustomer method needs to know the primary key or use some other unique field such as a name field to perform the update on the database.

    I have seen quite a few descriptions of the DTO/value object pattern in liturature such as the EJB Design Patterns book, but I don't see any examples or guidance on this issue.

       Nathan
  2. Helo,

    adding the ID value within the DTO to send back to the client won't be a big deal. in your case it may actually help you to solve the problem. *knowing* the ID does mean you can *update* the actual data within the database.

    exposing the ID to the client is another thing. look at this forum, see the querystring? there is a "message_id" there also.

    it should be fine...
    hope that help.
  3. Yes, that helps. Thanks. I guess that it is such a common practice and unlikely to change that it isn't an issue.

       Nathan