I'm trying to understand the canonical way to save relationships to existing nodes with Spring Data Neo4j and Spring Data REST. I have my domains model mapped out into entity classes and SDN repositories. I can successfully create a user or a campaign with simple properties listed, but when it comes time to create a new Campaign and tie it to an existing user, I'm not sure what to do in the JSON of the the request.
@Getter
@Setter
public abstract class Entity {
@Id
@GeneratedValue(strategy = UuidStrategy.class)
@Convert(UuidConverter.class)
private UUID eid;
}
@Getter
@Setter
@NodeEntity
public class User extends Entity {
@Required
@Index(unique = true)
private String username;
@Required
@Index(unique = true)
private String email;
@Relationship("CAMPAIGN_OWNER")
private List<Campaign> campaignsOwned;
}
@Getter
@Setter
@NodeEntity
public class Campaign extends Entity {
@Required
private String name;
@Required
@Relationship(type = "CAMPAIGN_OWNER", direction = Relationship.INCOMING)
private User owner;
}
And the repository interfaces
public interface UsersRepository extends Neo4jRepository<User, UUID> {
User findByUsername(@Param("username") String username);
User findByEmail(@Param("email") String email);
}
public interface CampaignsRepository extends Neo4jRepository<Campaign, UUID> {
}
Any help would be greatly appreciated. I've been searching the reference doc for Spring Data Neo4j and StackOverflow for a hours now and feel like I'm missing something.