Hi,
As a workaround, you can add a private getter method.
Christian
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Frédéric Camblor
Envoyé : October-17-12 3:22 AM
À : mybati...@googlegroups.com
Objet : Re: ResultMaps : Injecting collection without having any getter
No advice about this topic ?
FTM, I only found 2 workarounds :
Am I wrong ? (I would love to be wrong ! :-))
On Sat, Oct 13, 2012 at 1:50 PM, Frédéric Camblor <fcam...@gmail.com> wrote:
Hi folks !
I have a relatively simple case, something like this :
public class Foo {
private List<Bar> bars;
public void List<Bar> getBars(){
return this.bars;
}
// I don't want to provide a Bars setter to the outside of my bean
// I only want to create bars from quixes I retrieve from db
public void setQuixes(List<Quix> quixes){
this.bars = convertQuixesToBars(quixes);
}
private List<Bar> convertQuixesToBars(List<Quix> quixes){ ... }
}
In my mapping file, I'll have something like this :
<resultMap id="Quix" type="foo.Quix">....</resultMap>
<resultMap id="Foo" type="foo.Foo">
<collection property="quixes" resultMap="Quix" columnPrefix="quixes." />
</resultMap>
When mapping occurs, I catch an exception :
There is no getter for property named 'quixes' in 'class foo.Foo
Seems like MyBatis needs a collection getter in order, I suppose, to successively call add() on it.
I was just wondering : would there be a way to tell Mybatis to create the collection "externally" and the inject it via the setter method only (without calling the getQuixes() any time) ?
Thanks in advance,
Actually MyBatis can use any private getter/setter.
MyBatis can also handle fields (even private) that have no getter/setter, POJOs for example.
Christian
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Poitras Christian
Envoyé : October-17-12 9:04 AM
À : 'mybati...@googlegroups.com'
Objet : RE: ResultMaps : Injecting collection without having any getter