Version 1.1.11
I have a massive model with many circular dependencies (bi-direction mappings). Im using setNull to break the circular dependencies, and im using map(...) to persist some dependent children into the database as the sample is generated.
However even though the circular dependency has been broken, an object for that property (which eventually results in null) is still created along withs its children. Due to how im using map, some of these redundant objects are getting persisted.
After much exploring of the API, I couldnt find a customization that prevents generation of redundant parts of the object graph.
Below is a small example to illustrate the problem described above.
Let me know if there is customization to stop creation of redundant parts of the graph or if i should use a different strategy all together.
Many thanks.
@Data
@Entity
@NoArgsConstructor
public static class Foo {
private Bar bar;
private String f;
public void setBar(Bar bar) {
this.bar = bar;
this.bar.setFoo(this);
}
}
@Entity
@Data
@NoArgsConstructor
public static class Bar {
@ToString.Exclude
private Foo foo;
private String b;
}
FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.register(Foo.class, fm -> fm.giveMeBuilder(Foo.class)
.map(o -> persist(o))
)
.register(Bar.class, fm -> fm.giveMeBuilder(Bar.class)
.map(o -> persist(o))
)
Foo foo = fixtureMonkey.giveMeBuilder(Foo.class)
.map(o -> persist(o))
.sample();
//returns a Foo with a Bar with a different Foo and null Bar
Foo sample = fixtureMonkey.giveMeBuilder(Foo.class)
.setNull("bar.foo") //cyclic reference
.sample();
//returns a Foo with a Bar with the parent Foo (populated by bar.setFoo). However a distinct Bar and a distinct Foo is also constructed, the foo is persisted, but then they are discarded.
Version 1.1.11
I have a massive model with many circular dependencies (bi-direction mappings). Im using setNull to break the circular dependencies, and im using map(...) to persist some dependent children into the database as the sample is generated.
However even though the circular dependency has been broken, an object for that property (which eventually results in null) is still created along withs its children. Due to how im using map, some of these redundant objects are getting persisted.
After much exploring of the API, I couldnt find a customization that prevents generation of redundant parts of the object graph.
Below is a small example to illustrate the problem described above.
Let me know if there is customization to stop creation of redundant parts of the graph or if i should use a different strategy all together.
Many thanks.
//returns a Foo with a Bar with a different Foo and null Bar
//returns a Foo with a Bar with the parent Foo (populated by bar.setFoo). However a distinct Bar and a distinct Foo is also constructed, the foo is persisted, but then they are discarded.