Menu

Replicator wont invoke private setters

Help
Valy Sivec
2008-11-25
2013-04-25
  • Valy Sivec

    Valy Sivec - 2008-11-25

    Hello,  I have a bean with a private method setProperty. It looks that when replicating the bean the set method does not get invoked if the method is private.

    I assume that this is by desing. I just want to confirm this.

    Thanks,

    public class TestObject implements Serializable {

       
        private String uid;

       
        public String getUid() {
            return uid;
        }

        public void setUid(String uid) {
            this.uid = uid;
        }

        public String toString(){
            return "Value :" + uid ;
        }

       
        public TestObject(){
           this.uid = new UID().toString();    
        }
       
       
    }

     
    • Valy Sivec

      Valy Sivec - 2008-11-26

      Thanks - I will give it a try.

      Would you please share with us what new features you want to include in the v5.0?

       
      • Hanson Char

        Hanson Char - 2008-11-26

        Have you looked at the release notes ?  Hopefully they make sense.  I've also added some (quick start) documentation which you can find the link from the home page.

         
    • Hanson Char

      Hanson Char - 2008-11-26
       
    • Valy Sivec

      Valy Sivec - 2008-11-26

      Is version 5 in the early stages? I see that the examples you have are based on v.5.

      I'm using 3.21 beta now  and tried using:

      HibernateBeanReplicator replicator = new Hibernate3BeanReplicator().initSetterMethodCollector( PrivateSetterMethodCollector.inst ).initCustomTransformer(new MyCustomBeanTransformer.Factory());

      It seems that the private method are not invoked.

      Thanks,

      Valy Sivec

       
      • Hanson Char

        Hanson Char - 2008-11-27

        It works in both 5.0.0beta and 3.3.0beta21.  In fact, it would work in all versions since released.  Do you have a test code that can demonstrate this problem ?

         
        • Hanson Char

          Hanson Char - 2008-11-27

          The problem you encountered could be related to invoking the incorrect copy method.  In particular, if you invoke either deepCopy or shallowCopy on HibernateBeanReplicator, the initSetterMethodCollector will be ingored.  Javadoc extracted below:

          "HibernateBeanReplicator net.sf.beanlib.hibernate.HibernateBeanReplicator.initSetterMethodCollector(BeanMethodCollector setterMethodCollector)
          Used to configure a collector to collect the property setter methods of a target JavaBean.

          Note this method is only applicable if either the copy(Object) or copy(Object, Class) is directly invoked, and is ignored otherwise (ie ignored if deep or shallow copy is invoked instead)."

          In other words, if you want to override the setter method collector, you need to invoke the copy method directly and specify the whatever options as needed.

           
    • Hanson Char

      Hanson Char - 2008-11-27
       
      • Hanson Char

        Hanson Char - 2008-11-27

        On more thoughts, it makes little sense why deepCopy should always force the use of protected setter collector. 

        I am thinking of changing that in 5.x so the deepCopy/shallowCopy API would just work as expected in conjunction with the initSetterMethodCollector.  Least surprise to the programmer has the benefit of requiring less javadoc and less FAQ.

         
        • Joe D. Velopar

          Joe D. Velopar - 2008-11-28

          Beanlib 5.0.1beta released, which basically makes this issue a mute problem.

           

Log in to post a comment.