1 Reply Latest reply on Oct 20, 2005 6:43 PM by epbernard

    Collection

    martinganserer

      Hi,

      I have a strange behaviour in my app. I created a OneToMany-Relationship: I have an article entity bean and a bom item entity bean.
      One article has many bom items.

      @OneToMany(mappedBy="article",cascade=CascadeType.ALL)
       @JoinColumn(name="article", referencedColumnName="article_no")
       public Collection<BoMItem> getBom()
       {
       return bom;
       }
      
      
      
      


      /**
       * @return the article.
       */
       @ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,optional=false)
       @JoinColumn(name="article")
       public Article getArticle()
       {
       return article;
       }


      I created following test scenario:

      Article impArticle = articleBSI.getArticleById(article.getArticleNo());
       System.out.println(impArticle.getArticleNo() + " " + impArticle.getDescription());
       for(BoMItem bomItem : article.getBom())
       {
       System.out.println(bomItem.getId() + " " + bomItem.getPart().getPartNo() + " " + bomItem.getQuantity());
       }
       //impArticle.removeAllBoMItems();
      
       System.out.println("BoM:");
       for(BoMItem bomItem : article.getBom())
       {
       impArticle.addBoMItem(bomItem);
       }


      My addBoMItem-method looks like this:

      public void addBoMItem(BoMItem item)
       {
       item.setArticle(this);
       bom.add(item);
       }


      Without doing a merge of my article object the bom items will be persisted!! Can somebody please tell me the reason for that action? This behaviour is not what I expect when expecting cascades.