---
title: "Comment by Rainer Scholz on \"Replace a JPA entity with a DTO\" | Hashnode"
description: "Hi Maddy, I wonder how an public CustomerDTO updateCustomer(CustomerDTO customerDTO) would be implemented by you? My straight forward solution would be: public"
url: "https://hashnode.com/posts/replace-persistence-entity-with-a-dto-object/6294a0244dbee2dc251e3843/comment/631b4a3df73f4734bc0517e8"
---

[Discussion](https://hashnode.com/posts/replace-persistence-entity-with-a-dto-object/6294a0244dbee2dc251e3843)

Comment [Replace a JPA entity with a DTO](https://hashnode.com/posts/replace-persistence-entity-with-a-dto-object/6294a0244dbee2dc251e3843)

[Rainer Scholz](https://hashnode.com/@rainer619)

[Sep 9, 2022](https://hashnode.com/posts/replace-persistence-entity-with-a-dto-object/6294a0244dbee2dc251e3843/comment/631b4a3df73f4734bc0517e8)

Hi Maddy,

I wonder how an `public CustomerDTO updateCustomer(CustomerDTO customerDTO)` would be implemented by you?

My straight forward solution would be:

```
public CustomerDTO updateCustomer(CustomerDTO customerDTO)
{
   Customer customer = customerRepository.getReferenceById(customerDTO.getId());
   customer.setFirstName(customerDTO.getFirstName());
   customer.setLastName(customerDTO.getLastName());
   // ... repeated for all fields

  customerRepository.save(customer);
}
```

Note: The `CustomerDTO` requires some kind of resource identifier. I used the primary key of the database table.
