title: Spring Data REST URI vs. entity ID
body: <p>Spring Data REST (and Spring HATEOAS in particular) decouples RESTful IDs (viz., URIs) from entity IDs, and I'm having trouble linking them back up when saving new objects. See the interesting discussion around this decoupling at <a href="https://github.com/SpringSource/spring-data-rest/issues/13" rel="noreferrer">https://github.com/SpringSource/spring-data-rest/issues/13</a>.</p>
  
  <p>Suppose that a client app wants to create a new <code>Ticket</code> resource with an associated <code>TicketCategory</code> resource. I want to post the <code>Ticket</code> against a remote Spring Data REST endpoint. The <code>Ticket</code> doesn't yet have an ID since it's new. The <code>TicketCategory</code> has an ID, but on the client it's a URI per the discussion above. So when I save the <code>Ticket</code>, Spring Data REST passes the <code>Ticket</code> to Spring Data JPA, which doesn't like it: Spring Data JPA thinks that the <code>TicketCategory</code>&mdash;having no entity ID&mdash;is transient:</p>
  
  <pre><code>org.hibernate.TransientPropertyValueException:
      Not-null property references a transient value -
      transient instance must be saved before current operation:
      com.springinpractice.ch13.helpdesk.model.Ticket.category -&gt;
      com.springinpractice.ch13.helpdesk.model.TicketCategory
  </code></pre>
  
  <p><strong>UPDATE:</strong> The documentation at</p>
  
  <p><a href="https://github.com/SpringSource/spring-data-rest/wiki/JPA-Repository-REST-Exporter" rel="noreferrer">https://github.com/SpringSource/spring-data-rest/wiki/JPA-Repository-REST-Exporter</a></p>
  
  <p>has a section called "Updating relationships" that describes a scheme using HTTP POST to establish relationships between entities. I don't know if that's the only approach currently available, but it seems that this approach would require leaving the association null on the initial post and then updating it with a subsequent post. In the case above that would be undesirable since the category field is required (<code>@NotNull</code>) for tickets.</p>