Hydrated AND non-cumulative

Help
shabata
2005-09-13
2013-05-02
  • shabata

    shabata - 2005-09-13

    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

    • Ben Sullins

      Ben Sullins - 2005-09-13

      this should work, let me check our unit tests and get back to you.

       
    • shabata

      shabata - 2005-09-14

      so....
      Does it work ?

       
    • Ben Sullins

      Ben Sullins - 2005-09-14

      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.

       
    • shabata

      shabata - 2005-09-15

      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

       
    • Ben Sullins

      Ben Sullins - 2005-09-20

      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

       
    • shabata

      shabata - 2005-09-23

      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 ?

       
    • shabata

      shabata - 2005-09-23

      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.

       
    • Ben Sullins

      Ben Sullins - 2005-09-23

      yep, that would be a defect.  will fix that right away.

       
    • Ben Sullins

      Ben Sullins - 2005-09-23

      This is fixed, not sure when we will put it out, I will check with Franz.

      Ben

       
      • Franz Garsombke

        Franz Garsombke - 2005-09-23

        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

         
    • Ben Sullins

      Ben Sullins - 2005-09-23

      the fix was exactly as he stated.

       
    • shabata

      shabata - 2005-09-26

      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.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks