DozerMapper / dozer

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.
https://dozermapper.github.io/
Apache License 2.0
2.08k stars 481 forks source link

StackOverflow: null infinite recursion #704

Closed heloufir closed 5 years ago

heloufir commented 5 years ago

Runtime

Project details

I am developping a project based on SpringBoot and Hibernate, using DozerMapper/dozer repository.

Problem

Steps to reproduce:

  1. I just save the object into the database
  2. After the object is saved, I refresh the page
  3. I get the error StackOverFlow: null
  4. I have to restart the server to get the error fixed automatically

I have had this same error when I was using the net.sf.dozer repository, after I switched to this repository (DozerMapper/dozer) for a while I get the error fixed, but now it's back

Please I need help

heloufir commented 5 years ago

@garethahealy can you please take a look to this issue.

garethahealy commented 5 years ago

@eloufirhatim ; i've not had much free time recently to work on dozer issues. But if you create a github repo with an example showing the problem, it makes it easier to debug/check what you are trying to do.

heloufir commented 5 years ago

@garethahealy Sorry for bothering you, unfertunotely the project is big and it's private, so I can't push it into a github repository, but I can give you all the information that you wan't when you have some free time. Thanks again

garethahealy commented 5 years ago

@eloufirhatim ; can you slim it down? it can map fake data/doesn't have to involve the web bits you mentioned. but i need a reproducible bit of code to look at which fails 100% (or as near as possible)

heloufir commented 5 years ago

@garethahealy Okay, I'll see how I can prepare a scenario to get you as close as possible to the error. Thanks a lot

heloufir commented 5 years ago

I just got it working by changing a lit bit in my mapping xml file.

I changed my mappings from:

<mapping map-id="MAPPING_HAB_USER" map-empty-string="false"
    map-null="false" wildcard="false">
    <class-a>com.intranet.si.model.habilitation.User</class-a>
    <class-b>com.intranet.si.dto.habilitation.UserDTO</class-b>
    <field>
        <a>id</a>
        <b>id</b>
    </field>
    <field>
        <a>userName</a>
        <b>userName</b>
    </field>
    <field>
        <a>isOnline</a>
        <b>isOnline</b>
    </field>
    <field map-id="MAPPING_USER_EMPLOYEE">
        <a>refEmployee</a>
        <b>refEmployee</b>
    </field>
</mapping>

With the MAPPING_USER_EMPLOYEE

<mapping map-id="MAPPING_USER_EMPLOYEE" map-empty-string="false"
    map-null="false" wildcard="false">
    <class-a>com.intranet.si.model.hr.Employee</class-a>
    <class-b>com.intranet.si.dto.hr.EmployeeDTO</class-b>
    <field>
        <a>id</a>
        <b>id</b>
    </field>
    <field>
        <a>firstName</a>
        <b>firstName</b>
    </field>
    <field>
        <a>lastName</a>
        <b>lastName</b>
    </field>
</mapping>

To this signle mapping

<mapping map-id="MAPPING_HAB_USER" map-empty-string="false"
    map-null="false" wildcard="false">
    <class-a>com.intranet.si.model.habilitation.User</class-a>
    <class-b>com.intranet.si.dto.habilitation.UserDTO</class-b>
    <field>
        <a>id</a>
        <b>id</b>
    </field>
    <field>
        <a>userName</a>
        <b>userName</b>
    </field>
    <field>
        <a>isOnline</a>
        <b>isOnline</b>
    </field>
    <field>
        <a>refEmployee.id</a>
        <b>refEmployee.id</b>
    </field>
    <field>
        <a>refEmployee.firstName</a>
        <b>refEmployee.firstName</b>
    </field>
    <field>
        <a>refEmployee.lastName</a>
        <b>refEmployee.lastName</b>
    </field>
</mapping>

I used to use this option Context Based Mapping like said in the DozerMapper GitBook, but in some cases this mapping is broken, for exemple if I launch the application directly in the Employee view it's working without any error, but if I go to another view (a specific one) and return to the Employee view, here the mapping is borken, and instead of getting only id, firstName and lastName of the refEmployee of the user, I got all the columns, references, list, ... of the refEmployee object.

So the issue is gone when I specify directly the value that I want in the first mapping without using any other mapping in it.

If possible that you explain to me, if I did something wrong.

Thank you for your help.