5 Replies Latest reply on May 18, 2006 7:12 PM by Emmanuel Bernard

    Cascade problem

    blalls asdsd Novice

      I have a code like this:

      @OneToMany(mappedBy = "ne", cascade={CascadeType.REMOVE,CascadeType.REFRESH})
       @Column(unique = false, nullable=false)
       @Basic(fetch=FetchType.LAZY)
       public List<Activity> getActvs() {
       return actvs;
       }
      

      and I expect that when I am removing one instance of this class the its Actvs would be removed, but it is not! the Actvs stays there.

        • 1. Re: Cascade problem
          Cyril JOUI Newbie

          I have this code and it works fine :

           @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy="portfolio")
           public Collection<FinancialProduct> getFinancialProducts() {
           return financialProducts;
           }
          


          Try to remove :
           @Column(unique = false, nullable=false)
           @Basic(fetch=FetchType.LAZY)
          




          • 2. Re: Cascade problem
            blalls asdsd Novice

             

            "cyril.joui@supinfo.com" wrote:
            I have this code and it works fine :

             @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy="portfolio")
             public Collection<FinancialProduct> getFinancialProducts() {
             return financialProducts;
             }
            


            Try to remove :
             @Column(unique = false, nullable=false)
             @Basic(fetch=FetchType.LAZY)
            



            But the ollection is heavy and I need Lazy. What is your Jboss &EJB3 version?

            • 3. Re: Cascade problem
              Cyril JOUI Newbie

              Collections are always LAZY by default ... isn't it ?

              I have tested it with JBOSS 4.0.4RC1 (EJB3 RC ... ?) and CR2 (EJB3 RC6)

              • 4. Re: Cascade problem
                Andrew Elegante Newbie

                I'm having the same problem. I have a OneToMany relationship and regardless of whether I remove an object from the relationship, clear all of the objects in the relationship or replace the relationship with a new empty set the changes are never propagated to the 'Many' table.

                Here is how I have things mapped

                In Test1.java:

                @OneToMany( fetch = FetchType.LAZY, mappedBy = "test1Id")
                 public Set<Test2> getTest2s() {
                 return this.test2s;
                 }
                

                In Test2.java:
                @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
                 @JoinColumn(name = "TEST1ID", unique = false, nullable = false, insertable = true, updatable = true)
                 public Test1 getTest1() {
                 return this.test1;
                 }
                


                I've also tried this with just having the primitive Id field in Test2 and no mapping at all but regardless of how I perform the operation it doesn't work. We're using Jboss 4.0.4 cr2

                Anyone have an idea what is going on and/or how to fix it?

                thanks,

                Drew

                • 5. Re: Cascade problem
                  Emmanuel Bernard Master

                  true by the very definition of mappedBy