title: Why the record is posted twice in the database?
body: <p>Can you tell me, why the record is posted twice in the database. I think. this happens because I use <strong>save()</strong> method. But shouldn't I save the master-entity and dependent-entity separately?</p>
  
  <pre><code>Controller method:
  @RequestMapping(value = "/addComment/{topicId}", method = RequestMethod.POST)
  public String saveComment(@PathVariable int topicId, @ModelAttribute("newComment")Comment comment, BindingResult result, Model model){
          Topic commentedTopic = topicService.findTopicByID(topicId);
          commentedTopic.addComment(comment);
  
          // TODO: Add a validator here
          if (!comment.isValid() ){
              return "//";
  
          }
          // Go to the "Show topic" page
          commentService.saveComment(comment);
  
          return "redirect:../details/" + topicService.saveTopic(commentedTopic);
  
  }
  </code></pre>
  
  <p>Services: </p>
  
  <pre><code>@Service
  @Transactional
  public class CommentService {
  
      @Autowired
      private CommentRepository commentRepository;
  
      public int saveComment(Comment comment){
          return commentRepository.save(comment).getId();
  
      }   
  
  }
  
  @Service
  @Transactional
  public class TopicService {
      @Autowired
      private TopicRepository topicRepository;
  
      public int saveTopic(Topic topic){
          return topicRepository.save(topic).getId();
  
      }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>@Entity
  @Table(name = "T_TOPIC")
  public class Topic {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
      @ManyToOne
      @JoinColumn(name="USER_ID")
      private User author;
  
      @Enumerated(EnumType.STRING)    
      private Tag topicTag;
  
      private String name;
      private String text;
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "topic", cascade = CascadeType.ALL)
      private Collection&lt;Comment&gt; comments = new LinkedHashSet&lt;Comment&gt;();
  
  }
  
  @Entity
  @Table(name = "T_COMMENT")
  public class Comment
  {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
      @ManyToOne
      @JoinColumn(name="TOPIC_ID")
      private Topic topic;
  
      @ManyToOne
      @JoinColumn(name="USER_ID")
      private User author;
  
      private String text;
      private Date creationDate;
  }
  </code></pre>