title: POST a list of items spring boot
body: <pre><code>@RestController
  public class TopicController {
  
      @Autowired
      private TopicService topicService;
  
      @RequestMapping(value="/topics", method= RequestMethod.GET)
      public List&lt;Topic&gt; getAllTopics(){
          return topicService.getAllTopics();
      }
  
      @RequestMapping(value="/topics/{id}", method= RequestMethod.GET)
      public Topic getTopic(@PathVariable String id){
          return topicService.getTopic(id);
      }
  
      @RequestMapping(value="/topics", method= RequestMethod.POST)
      public void addTopic(@RequestBody Topic topic){
          topicService.addTopic(topic);
      }
  
      @RequestMapping(value="/topics/{id}", method= RequestMethod.PUT)
      public void updateTopic(@RequestBody Topic topic, @PathVariable String id){
          topicService.updateTopic(id, topic);
      }
  
      @RequestMapping(value="/topics/{id}", method= RequestMethod.DELETE)
      public void deleteTopic(@PathVariable String id){
          topicService.deleteTopic(id);
      }
  }
  </code></pre>
  
  <p>Controller class </p>
  
  <pre><code>@Service
  public class TopicService {
  
      @Autowired
      private TopicRepository topicRepo;
  
      public List&lt;Topic&gt; getAllTopics(){
          return (List&lt;Topic&gt;)topicRepo.findAll();
  
      }
  
      public Topic getTopic(String id){
          return topicRepo.findOne(id);
      }
  
      public void addTopic(Topic topic){
          //topics.add(topic);
  
          topicRepo.save(topic);
      }
  
      public void updateTopic(String id, Topic topic) {
          topicRepo.save(topic);
      }
  
      public void deleteTopic(String id) {
          //topics.removeIf(t -&gt; t.getId().equals(id));
  
          //topics.removeIf((Topic t) -&gt; t.getId().equals(id));
  
          topicRepo.delete(id);
  
      }
  
  }
  </code></pre>
  
  <p>Service Class</p>
  
  <pre><code>@Repository
  public interface TopicRepository extends CrudRepository&lt;Topic, String&gt;{
  
      //List&lt;Course&gt; findByTopic_Id(String topicid);
  
  }
  </code></pre>
  
  <p>Repository Class</p>
  
  <pre><code>@Entity
  public class Topic {
  
      @Id
      @Column(name="TOPIC_ID")
      private String id;
      @Column(name="NAME")
      private String name;
      @Column(name="DESCRIPTION")
      private String description;
  
      @OneToMany(mappedBy="topic", fetch = FetchType.EAGER)
      @JsonManagedReference
      private List&lt;Course&gt; course = new ArrayList&lt;Course&gt;();
  
      //no - argument constructor. Needed for hibernate
      public Topic(){};
  
      public Topic(String id, String name, String description, List&lt;Course&gt; course){
          super();
          this.id = id;
          this.name = name;
          this.description = description;
          this.course = course;
      }
  
      public Topic(String id, String name, String description){
          super();
          this.id = id;
          this.name = name;
          this.description = description;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
      public List&lt;Course&gt; getCourse() {
          return course;
      }
  
      public void setCourse(List&lt;Course&gt; course) {
          this.course = course;
      }
  }
  </code></pre>
  
  <p>Topic Class</p>
  
  <pre><code>@Entity
  public class Course{
  
      @Id
      @Column(name="COURSE_ID")
      private String id;
      private String name;
      private String description;
  
      //There could be many courses related to 1 topic
      @ManyToOne
      @JoinColumn(name = "TOPIC_ID")
      @JsonBackReference
      private Topic topic;
  
      public Course(){};
  
  
      public Course(String id, String name, String description){
  
          super();
          this.id = id;
          this.name = name;
          this.description = description;
  
      }
  
      public Topic getTopic() {
          return topic;
      }
  
      public void setTopic(Topic topic) {
          this.topic = topic;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
  }
  </code></pre>
  
  <p>Course Class</p>
  
  <p>I am trying to use Postman to post a Topic class which contains many Courses into my sql database. </p>
  
  <p>In Postman, I did the POST using JSON like this</p>
  
  <pre><code>{
      "id": "700",
      "name": "How to countt",
      "description": "Counting numbersssss",
      "course": [
        {
          "id": "1",
          "name": "php",
          "description": "gooddddyyyy stuff"
        },
        {
          "id": "2",
          "name": "phpp",
          "description": "gooddddyyyy stuffp"
        }
      ]
  }
  </code></pre>
  
  <p>However, when i do the corresponding get all topics, my response was </p>
  
  <pre><code>{
      "id": "700",
      "name": "How to countt",
      "description": "Counting numbersssss",
      "course": []
  }
  </code></pre>
  
  <p>It is not picking up the courses that i posted. One Topic can have many Courses. How do i fix this? Thank you</p>