Decathlon / Decathlon/tzatziki

Bidirectionnal relations go in infinite loop during check

Open
#633 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
87
Forks
42
Avg merge
4d 7h
Merged PRs (30d)
32

Description

Hello,
It's been several times I go through this error :
I have two entities that know each other :

```java
@Entity
public class CbdHardwareEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

/* other properties */

@OneToOne(mappedBy = "cbd", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
private CbdHardwareBomEntity bom;
}
```

```java
@Entity
public class CbdHardwareBomEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

/* other properties */

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_cbd_id", referencedColumnName = "id", columnDefinition = "integer")
private CbdHardwareEntity cbd;
}
```

And my tzatziki tests :

```gherkin
And that the CbdHardwareEntity entities will contain:
"""yml
- conceptionCode: 123456
"""
And that the CbdHardwareBomEntity entities will contain:
"""yml
- name: bom pace name
perimeter: perimeter pace
paceId: 50
cbd.id: 1
"""
```

When I do a `And the CbdHardwareEntity entities contain:` to check the content of my main table after I called my service, it goes into an infinite loop :
```
com.fasterxml.jackson.databind.JsonMappingException: Document nesting depth (1001) exceeds the maximum allowed (1000, from `StreamWriteConstraints.getMaxNestingDepth()`) (through reference chain: com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareEntity["bom"]->com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareBomEntity["cbd"]->com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareEntity["bom"]->com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareBomEntity["cbd"]->com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareEntity["bom"]->com.decathlon.buysmart.datacost.hardware.repository.models.CbdHardwareBomEntity["cbd"]-
```

I have tried the `@JsonManagedReference` and `@JsonBackReference`, it did work but I prefer not to modify my entities just to make tests work.

Do you have a solution to propose if I ever met this problem ? I will call my api to get resources to make the check I need; but it make more sense to directly check the content of a table.

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.