Nested entities in spring webflux

1.3k Views Asked by At

I am trying to use nested entities in spring webflux. I have an object User :

@Table
public class User {

    @Id private Long id;
    private String firstname;
    private String lastname;

    ...getters, setters, constructors
}

And an object Publication :

@Table
public class Publication {

    @Id private Long id;
    private User publisher;
    private String title;
    private String body;

    ...getters, setters, constructors
}

I am successfully retrieving publications with their users as follow :

    {
    "id": 1,
    "publisher": {
      "id": 1,
      "firstname": "John",
      "lastname": "Smith"
    }
    "title": "A title",
    "body": "A body"
    }

I would like to be able to post the same object when creating a new Publication, but when I do so, I am getting the error :

Nested entities are not supported.

My PublicationRepository :

@Repository
public interface PublicationRepository extends ReactiveCrudRepository<Publication, Long> {
}

PublicationService save :

public Mono<Publication> savePublication(Publication publication) {
  return publicationRepository.save(publication);
}

I could simply change user to userId in Publication, but that would imply making a new request to users table for each publication retreived.

0

There are 0 best solutions below