mahadevaprasad A M
mahadevaprasad A M

Reputation: 61

Dozer copy-by-reference not working

I have entities created by jpa tool and I have similar DTO's when I fetch entity from DB and try to mapping using dozer.

entities and DTO look like

class A                             class A1
        {                                   {
            private B b;                        private B1 b1;
            private C c;                        private C1 c;

            getter/setter                       getter/setter
        }

        class B                             class B1
        {                                   {                   
            private C c;                     private C1 c;

            getter/setter                       getter/setter
        }                                   }

        class C                             class C1
        {                                   {           
            private A a;                    private A1 a;
            private B b;                    private B1 b;

            getter/setter                   getter/setter
        }                                   }

Dozer mapping file looks like:

<mapping>
        <class-a>com.entity.A</class-a>
        <class-b>com.dto.A1</class-b>         
          <field copy-by-reference="true">
            <a>b</a>
            <b>b1</b>
          </field>
          <field copy-by-reference="true">
            <a>c</a>
            <b>c1</b>
          </field>
        </mapping>  

and I am getting exception like:

org.dozer.MappingException: Illegal object type for the method 'setb1'. 
 Expected types: 
com.dto.B1
 Actual types: 
com.entity.B

I am very new to Dozer please help me to solve this

Upvotes: 1

Views: 1637

Answers (1)

Koby
Koby

Reputation: 615

When using copy-by-reference, setters on both entities should be of the same type. Using this means that no conversion/transformation is done by Dozer, just a simple copy of the same object.

If you don't need this ability, remove the "copy-by-reference" property and it should work (assuming that you don't have any other complex types that Dozer can't transform automatically).

Upvotes: 2

Related Questions