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 https://github.com/SpringSource/spring-data-rest/issues/13.
Suppose that a client app wants to create a new Ticket
resource with an associated TicketCategory
resource. I want to post the Ticket
against a remote Spring Data REST endpoint. The Ticket
doesn't yet have an ID since it's new. The TicketCategory
has an ID, but on the client it's a URI per the discussion above. So when I save the Ticket
, Spring Data REST passes the Ticket
to Spring Data JPA, which doesn't like it: Spring Data JPA thinks that the TicketCategory
—having no entity ID—is transient:
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 ->
com.springinpractice.ch13.helpdesk.model.TicketCategory
UPDATE: The documentation at
https://github.com/SpringSource/spring-data-rest/wiki/JPA-Repository-REST-Exporter
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 (@NotNull
) for tickets.