title: How to modify Hibernate entity effectively(Using Java8 lambda's or anything else)
body: <p>I am having simple scenario when I am getting Entity from DB and modify it. </p>
  
  <p>I dont know which fields are being modified so I am just getting the current entity from db and set all values by the new DTO(newModifiedUserDTO). </p>
  
  <p>The code is getting cluttered, ugly and long. </p>
  
  <p>Maybe you could advice me(Using java 8's lambda's or any other Technic how to make this code shorter and effective ?</p>
  
  <pre><code> @Transactional
  @Override
      public void modifyUserEntity(UserEntityDTO newModifiedUserDTO) {
          UserEntity oldUserEntity = usersRepository.findByUsername(newModifiedUserDTO.getUsername());
  
          oldUserEntity.getExternalUsersEntity().setFirstName(newModifiedUserDTO.getExternalUsersEntity().getFirstName());
          oldUserEntity.getExternalUsersEntity().setLastName(newModifiedUserDTO.getExternalUsersEntity().getLastName());
          oldUserEntity.getExternalUsersEntity().setEnteredCompany(newModifiedUserDTO.getExternalUsersEntity().getEnteredCompany());
          oldUserEntity.getExternalUsersEntity().setCountry(newModifiedUserDTO.getExternalUsersEntity().getCountry());
          oldUserEntity.getExternalUsersEntity().setState(newModifiedUserDTO.getExternalUsersEntity().getState());
          oldUserEntity.getExternalUsersEntity().setCity(newModifiedUserDTO.getExternalUsersEntity().getCity());
          oldUserEntity.getExternalUsersEntity().setAddress1(newModifiedUserDTO.getExternalUsersEntity().getAddress1());
          oldUserEntity.getExternalUsersEntity().setAddress2(newModifiedUserDTO.getExternalUsersEntity().getAddress2());
          oldUserEntity.getExternalUsersEntity().setZipCode(newModifiedUserDTO.getExternalUsersEntity().getZipCode());
          oldUserEntity.getExternalUsersEntity().setTelephone(newModifiedUserDTO.getExternalUsersEntity().getTelephone());
          oldUserEntity.getExternalUsersEntity().setFax(newModifiedUserDTO.getExternalUsersEntity().getFax());
          oldUserEntity.getExternalUsersEntity().setShippingCountry(newModifiedUserDTO.getExternalUsersEntity().getShippingCountry());
          oldUserEntity.getExternalUsersEntity().setShippingState(newModifiedUserDTO.getExternalUsersEntity().getShippingState());
          oldUserEntity.getExternalUsersEntity().setShippingCity(newModifiedUserDTO.getExternalUsersEntity().getShippingCity());
          oldUserEntity.getExternalUsersEntity().setShippingZip(newModifiedUserDTO.getExternalUsersEntity().getShippingZip());
          oldUserEntity.getExternalUsersEntity().setShippingTelephone(newModifiedUserDTO.getExternalUsersEntity().getShippingTelephone());
          oldUserEntity.getExternalUsersEntity().setShippingFax(newModifiedUserDTO.getExternalUsersEntity().getShippingFax());
          oldUserEntity.getExternalUsersEntity().setShippingAddress1(newModifiedUserDTO.getExternalUsersEntity().getShippingAddress1());
          oldUserEntity.getExternalUsersEntity().setShippingAddress2(newModifiedUserDTO.getExternalUsersEntity().getShippingAddress2());
          oldUserEntity.getExternalUsersEntity().setWorkspace(newModifiedUserDTO.getExternalUsersEntity().getWorkspace());
          oldUserEntity.setModifyDate(CisUtils.getCurrentDate());
  
      }
  </code></pre>
  
  <p>According to some suggestions I tried to use Spring utils for this:</p>
  
  <pre><code> copyProperties(newModifiedUserDTO.getExternalUsersEntity(), modifiedUserEntity.getExternalUsersEntity(), "firstName", "lastName", "enteredCompany",
              "country", "state", "address1", "address2", "zipCode","telephone","fax","shippingCountry","shippingCity","shippingZip","shippingTelephone","shippingFax","shippingAddress1",
              "shippingAddress2","workspace");
  </code></pre>
  
  <p>But for some reason the changes weren't reflected in the database(using hibernate)</p>
  
  <p>any ideas?</p>
  
  <p>Thanks,
  ray.</p>