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();
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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();
}
}
See:
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-doc/bean-replicator.html#getters-and-setters
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-doc/hibernate-bean-replicator.html#getters-and-setters
Thanks - I will give it a try.
Would you please share with us what new features you want to include in the v5.0?
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.
Link to the release notes:
https://sourceforge.net/project/shownotes.php?group_id=140152&release_id=642941
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
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 ?
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.
Added an FAQ item for this:
http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib-doc/faq.html#why-private-setter-not-work
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.
Beanlib 5.0.1beta released, which basically makes this issue a mute problem.