I'm new to Dozer and I'm facing a problem :
-----------------------------------
HERE IS THE MODEL :
Class A{
List listeA1; //list of ObjectA1
List listeA2; //list of ObjectA2
}
Class B{
List listeB; //list of ObjectB
}
ObjectB1 extends ObjectB (and can be mapped to ObjectA1)
ObjectB2 extends ObjectB (and can be mapped to ObjectA2)
---------------------------------------------------------
XML MAPPING FILE :
[code]<mapping>
<classA>ObjectA</classA>
<classB>ObjectB</classB>
<field-hydrate>
<A>listeA1</A>
<B>listeB</B>
<sourceTypeHint>ObjectA1</sourceTypeHint>
<destinationTypeHint>ObjectB1</destinationTypeHint>
</field-hydrate>
<field-hydrate>
<A>listeA2</A>
<B>listeB</B>
<sourceTypeHint>ObjectA2</sourceTypeHint>
<destinationTypeHint>ObjectB2</destinationTypeHint>
</field-hydrate>
</mapping>[/code]
---------------------------------------------------
the mapping between ObjectA and ObjectB is working well, but the update of these objects is not. I defined the method "equals()" for the classes ObjectA* and ObjectB*, and I tried to modify the xml file, but it's always adding a new instance in the list instead of updating the object if it already exists.
Do you understand what I mean ?
<b>My question is : Is it possible to do both hydrating and updating lists or am I missing something ?</b>
well, I don't think so, but let me make sure I understand your problem:
essentially, you want to check if the exact object is already present in your list? I don't think we applied the cumuliative/non-cumulative stuff to hydrate/dehydrate.
will work on this one for you and get it out soon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yep, it's pretty similar to what I'm looking for :
-----------------------------------------------------------------
Let's have :
ObjectA oA =( listA1("dog","cat"), listA2("woman","man"))
->ObjectB oB=(ObjectB)Mapper.map(oA,ObjectB.class);
so oB is (listB("dog","cat","woman","man"))
->Mapper.map(oB,oA);
oA should not be modify, but actually it becomes :
( listA1("dog","cat","dog","cat"), listA2("woman","man","woman","man"))
--------------------------------------------------------------------
The solution might be to add the following line in the file "dozerbeanmapping.dtd" :
<!ATTLIST field-hydrate relationshipType (cumulative | non-cumulative ) "cumulative">
Don't you think so ?
Thanx for your help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is fixed, I added the ability to specify relationship type on the hydrate/dehydrate mappings. In the next release, which will be soon, you should have it.
ben
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But there's still a problem...it's not a simple one and it took me a long time to understand the failure.
The problem :
when you parse the mapping file, every mapping is cloned and reversed (in order to make the mapping bidirectional), but when you clone a genericfieldmap the RELATIONSHIPTYPE property is not cloned, therefore update of a list is not working from classB to classA.
The solution would be :
- MappingFileReader (line 163), add the code :
"((GenericFieldMap)fm).setRelationshipType(((GenericFieldMap)field).getRelationshipType());"
- or to overload the method "clone()" in the class GenericFieldMap
c what I mean ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But there's still a problem...it's not a simple one and it took me a long time to understand the failure.
The problem :
when you parse the mapping file, every mapping is cloned and reversed (in order to make the mapping bidirectional), but when you clone a genericfieldmap the RELATIONSHIPTYPE property is not cloned, therefore update of a list is not working from classB to classA.
The solution would be :
- MappingFileReader (line 163), add the code :
"((GenericFieldMap)fm).setRelationshipType(((GenericFieldMap)field).getRelationshipType());"
- or to overload the method "clone()" in the class GenericFieldMap
c what I mean ?
thanx,
Bertrand.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm new to Dozer and I'm facing a problem :
-----------------------------------
HERE IS THE MODEL :
Class A{
List listeA1; //list of ObjectA1
List listeA2; //list of ObjectA2
}
Class B{
List listeB; //list of ObjectB
}
ObjectB1 extends ObjectB (and can be mapped to ObjectA1)
ObjectB2 extends ObjectB (and can be mapped to ObjectA2)
---------------------------------------------------------
XML MAPPING FILE :
[code]<mapping>
<classA>ObjectA</classA>
<classB>ObjectB</classB>
<field-hydrate>
<A>listeA1</A>
<B>listeB</B>
<sourceTypeHint>ObjectA1</sourceTypeHint>
<destinationTypeHint>ObjectB1</destinationTypeHint>
</field-hydrate>
<field-hydrate>
<A>listeA2</A>
<B>listeB</B>
<sourceTypeHint>ObjectA2</sourceTypeHint>
<destinationTypeHint>ObjectB2</destinationTypeHint>
</field-hydrate>
</mapping>[/code]
---------------------------------------------------
the mapping between ObjectA and ObjectB is working well, but the update of these objects is not. I defined the method "equals()" for the classes ObjectA* and ObjectB*, and I tried to modify the xml file, but it's always adding a new instance in the list instead of updating the object if it already exists.
Do you understand what I mean ?
<b>My question is : Is it possible to do both hydrating and updating lists or am I missing something ?</b>
Related
Code: code
this should work, let me check our unit tests and get back to you.
so....
Does it work ?
well, I don't think so, but let me make sure I understand your problem:
essentially, you want to check if the exact object is already present in your list? I don't think we applied the cumuliative/non-cumulative stuff to hydrate/dehydrate.
will work on this one for you and get it out soon.
yep, it's pretty similar to what I'm looking for :
-----------------------------------------------------------------
Let's have :
ObjectA oA =( listA1("dog","cat"), listA2("woman","man"))
->ObjectB oB=(ObjectB)Mapper.map(oA,ObjectB.class);
so oB is (listB("dog","cat","woman","man"))
->Mapper.map(oB,oA);
oA should not be modify, but actually it becomes :
( listA1("dog","cat","dog","cat"), listA2("woman","man","woman","man"))
--------------------------------------------------------------------
The solution might be to add the following line in the file "dozerbeanmapping.dtd" :
<!ATTLIST field-hydrate relationshipType (cumulative | non-cumulative ) "cumulative">
Don't you think so ?
Thanx for your help
This is fixed, I added the ability to specify relationship type on the hydrate/dehydrate mappings. In the next release, which will be soon, you should have it.
ben
Thank you !
But there's still a problem...it's not a simple one and it took me a long time to understand the failure.
The problem :
when you parse the mapping file, every mapping is cloned and reversed (in order to make the mapping bidirectional), but when you clone a genericfieldmap the RELATIONSHIPTYPE property is not cloned, therefore update of a list is not working from classB to classA.
The solution would be :
- MappingFileReader (line 163), add the code :
"((GenericFieldMap)fm).setRelationshipType(((GenericFieldMap)field).getRelationshipType());"
- or to overload the method "clone()" in the class GenericFieldMap
c what I mean ?
Thank you !
But there's still a problem...it's not a simple one and it took me a long time to understand the failure.
The problem :
when you parse the mapping file, every mapping is cloned and reversed (in order to make the mapping bidirectional), but when you clone a genericfieldmap the RELATIONSHIPTYPE property is not cloned, therefore update of a list is not working from classB to classA.
The solution would be :
- MappingFileReader (line 163), add the code :
"((GenericFieldMap)fm).setRelationshipType(((GenericFieldMap)field).getRelationshipType());"
- or to overload the method "clone()" in the class GenericFieldMap
c what I mean ?
thanx,
Bertrand.
yep, that would be a defect. will fix that right away.
This is fixed, not sure when we will put it out, I will check with Franz.
Ben
Ben -
Can you list the Class you patched...and what you changed? I want to wait awhile for a new release...to let things harden.
After listing this...shabata can change and recompile until our new release.
To build dozer (I should document this) just install maven 1.0.x and type -
maven clean site jar. The jar is in the {dozer}/targets directory.
If you want a full jar...after running maven type: (you need ant)
ant jar-full and it will generate the full jar in {dozer}/dist
thanks,
franz
the fix was exactly as he stated.
Thanks guys !
Don't worry about the release. I think it's better to wait for a bigger release than to put one out every week.
Bertrand.