atos1990 / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

How to handle infinit recursion for entities with bidirectional many-to-many relations #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I'm using Orika to map data from Hibernate Entity Objects to Value Objects. 
I've got 3 entities: Project, ProjectItem and InvoiceItem

In pseudocode this would be something like this

Entity: Project
One-To-Many to ProjectItem

Entity: ProjectItem
Many-To-Many to InvoiceItem: Set<InvoiceItem> invoiceItems;

Entity: InvoiceItem
Many-To-Many to ProjectItem: Set<ProjectItem> projectItems;

As you can see I've a bidirectional many-to-manny mapping between ProjectItem 
and InvoiceItem.

If I have a project object with at least one projectitem and a projectitem has 
at least one invoice item. And I try to map ProjectItem to ProjectItemVO with 
orika, I'm in an endles loop due to the recursive mapping of orika.

I'm not telling here that this is a bug, but I rather want to know how this 
infinit recusion can be avoided.

What is the expected output? What do you see instead?
I expect Orika to map the object only one and not to map all recursive object 
until without stopping.

What version of the product are you using? On what operating system?
Version is 1.3.5. Operating system is MAC OS Mountain Lion.

Original issue reported on code.google.com by koendec...@nspire.be on 20 Nov 2012 at 7:55

GoogleCodeExporter commented 9 years ago
I was not reproduce the endless loop with your example,
please take a look at the joined  TestCase and confirm if this is your real 
case.
Otherwise please complete this tests and send it again.

Thank you.

Original comment by elaat...@gmail.com on 20 Nov 2012 at 11:00

Attachments:

GoogleCodeExporter commented 9 years ago
Dear,

my situation is a bit different because i've interfaces for each entity object 
because I want to split my service and my persistence layer. There for I'm 
using a BeanFactory for the creation of my entity objects and the bean factory 
methods only return objects of the interface types. Also my problem is 
occurring when casting from the value object to the persistence object. I've 
adjusted your unit test accordingly to my situation. Unfortunately I'm having a 
different issue in the unit test than the 'infinit recursion' issue I'm having 
in my application. The error I'm having in the attached test case is "No 
concrete class mapping defined for source class". Maybe this is also causing 
the endless loop in my application. I hope you can figure this out.

Koen

Original comment by koendec...@nspire.be on 20 Nov 2012 at 10:24

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 22 Nov 2012 at 2:22

GoogleCodeExporter commented 9 years ago
Could you please check the latest release (1.4.0) and verify whether this was 
fixed for you?

Original comment by matt.deb...@gmail.com on 19 Dec 2012 at 2:03

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 8 Mar 2013 at 9:03