title: Spring Data Rest: POSTing entity with relation to non-exported entity
body: <p>I have an entity type that is exported via Spring Data Rest and has a relation to an entity which does not have it's own REST endpoint:</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @EqualsAndHashCode
  @Entity
  public class Request {
  
      ...
  
      @NotNull
      @OneToOne(cascade = CascadeType.ALL)
      @Immutable
      private Address address;
  </code></pre>
  
  <p>The "Address" type looks roughly like this plus the usual stuff for addresses ;)</p>
  
  <pre><code>@NoArgsConstructor
  @Entity
  @Getter
  @Setter
  public class Address {
  
      @Id
      @GeneratedValue
      private Long id;
  </code></pre>
  
  <p>There is a RequestRepo that extends CrudRepository but NO repository for the address type.</p>
  
  <p>This is what I do:
  1. GET a particular Request entity
  2. Make a change to a property of Request (not address)
  3. PUT the entire Request</p>
  
  <p>I noticed, in the handler's @BeforeSave annotated method, that the address property has an id of "null". So it appears that instead of looking for that Address in the database, it simply created a new one.</p>
  
  <p>Well, I understand that since the id is not POSTed there's not way to know which Address in the database this is supposed to be. That makes sense.</p>
  
  <p>In the handler, I want to check if the address has been changed and then do things based on that information. Therefore, I fetch the old version of the Request from the database and compare the IDs of the two Addresses which of course results in a NullPointerException, since the ID of the posted Address is null. My quick solution would be to implement equals() omitting the ID and use that method to make the comparison.</p>
  
  <p>But I wonder what other ways there might be. Any ideas?</p>