Hello @t.vignal,
I’ve tried to reproduce the problem using next entities:
@Entity(name = "test_JpaCascadeParent")
@JmixEntity
@Table(name = "TEST_JPA_CASCADE_PARENT")
public class JpaCascadeParent extends BaseEntity {
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "FOO_ID")
@Composition
private JpaCascadeFoo foo;
@Column(name = "NAME")
private String name;
//...
}
// ---------------------------------------------------------------
@Entity(name = "test$JpaCascadeFoo")
@JmixEntity
@Table(name = "TEST_JPA_CASCADE_FOO")
public class JpaCascadeFoo extends BaseEntity {
@Column(name = "NAME")
private String name;
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@Composition
@JoinColumn(name = "BAR_ID")
private JpaCascadeBar bar;
//...
}
//-----------------------
@Entity(name = "test$JpaCascadeBar")
@JmixEntity
@Table(name = "TEST_JPA_CASCADE_BAR")
public class JpaCascadeBar extends BaseEntity {
@Column(name = "NAME")
private String name;
//...
}
And test:
def "check nested cascade events"(){
setup:
TestCascadeFooEventListener.clear()
TestCascadeBarEventListener.clear()
when: "cascade persist occurs"
def foo = dataManager.create(JpaCascadeFoo)
foo.name = "testFoo"
def bar = dataManager.create(JpaCascadeBar)
bar.name = "testBar"
foo.setBar(bar)
def parent = dataManager.create(JpaCascadeParent)
parent.name = "testParent"
parent.setFoo(foo)
dataManager.save(parent)
def barChangedEvents = TestCascadeBarEventListener.allEvents
def fooChangedEvents = TestCascadeFooEventListener.allEvents
then: "All events present for cascade-persisted entity"
barChangedEvents.size() == fooChangedEvents.size()
barChangedEvents.stream().anyMatch(info -> info.message == "AfterInsertEntityListener")
barChangedEvents.stream().anyMatch(info -> info.message == "BeforeInsertEntityListener")
barChangedEvents.stream().anyMatch(info -> info.message == "BeforeDetachEntityListener")
barChangedEvents.stream().anyMatch(info -> info.message == "EntitySavingEvent: isNew=true")
barChangedEvents.stream().anyMatch(info -> info.message == "EntityChangedEvent: beforeCommit, CREATED")
barChangedEvents.stream().anyMatch(info -> info.message == "EntityChangedEvent: afterCommit, CREATED")
barChangedEvents.stream().anyMatch(info -> info.message == "EntityLoadingEvent")
fooChangedEvents.stream().anyMatch(info -> info.message == "AfterInsertEntityListener")
fooChangedEvents.stream().anyMatch(info -> info.message == "BeforeInsertEntityListener")
fooChangedEvents.stream().anyMatch(info -> info.message == "BeforeDetachEntityListener")
fooChangedEvents.stream().anyMatch(info -> info.message == "EntitySavingEvent: isNew=true")
fooChangedEvents.stream().anyMatch(info -> info.message == "EntityChangedEvent: beforeCommit, CREATED")
fooChangedEvents.stream().anyMatch(info -> info.message == "EntityChangedEvent: afterCommit, CREATED")
fooChangedEvents.stream().anyMatch(info -> info.message == "EntityLoadingEvent")
}
(this test is based on https://github.com/jmix-framework/jmix/blob/master/jmix-data/eclipselink/src/test/groovy/cascade_operations/CascadeEventsTest.groovy)
Unfortunately, it was no success in problem reproduction: test passed.
Maybe I miss or misunderstood something?
Could you please provide a sample project where the problem can be reproduced?
Regards,
Dmitry