I'm having trouble figuring out exactly how to use the @RepositoryRestResource interface to create many-to-many relationships between two fairly simple entities.
For example, I have a simple parent-child entity relationship like this:
@Entity
public class ParentEntity {
@Id
@GeneratedValue
private Long id;
@ManyToMany
private List<ChildEntity> children;
}
@Entity
public class ChildEntity {
@Id
@GeneratedValue
private Long id;
@ManyToMany(mappedBy="children")
private List<ParentEntity> parents;
}
My repositories are using the vanilla Spring @RepositoryRestResource HATEOS API:
@RepositoryRestResource(collectionResourceRel = "parents", path = "parents")
public interface ParentRepository extends PagingAndSortingRepository<ParentEntity, Long> {
}
@RepositoryRestResource(collectionResourceRel = "children", path = "children")
public interface ChildRepository extends PagingAndSortingRepository<ChildEntity, Long> {
}
I’ve been successful in using POST to create the individual ParentEntity and ChildEntity but I can’t seem to figure out how to PUT/PATCH the relationships between the two using the built-in interface.
It seems like I should be able to use a PUT to send JSON to something like http://localhost:8080/api/parents/1/children
, but so far I'm not finding a structure that works.