Can't persist class

hello again, I am using dataManager in a service, in order to persist some data. But for some reason it does not allow me to persist anything

the stack trace says:

java.lang.IllegalStateException: An attempt to save an entity with reference to some not persisted entity. All newly created entities must be saved in the same transaction. Put all these objects to the CommitContext before commit.
at com.haulmont.cuba.core.sys.aop.CascadePersistExceptionAspect.changeCascadePersistMessage(CascadePersistExceptionAspect.java:38) ~[cuba-core-7.2.5.jar:7.2.5]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]

Hi,

The recommendations are printed in the error message:

java.lang.IllegalStateException: An attempt to save an entity with reference to some not persisted entity. All newly created entities must be saved in the same transaction. Put all these objects to the CommitContext before commit.

So if you have two entities: Foo and Bar, and Foo.bar attribute is a reference to Bar, and you create both entities, then pass them both to the DataManager:

Foo foo = dataManager.create(Foo.class);
Bar bar = dataManager.create(Bar.class);
foo.setBar(bar);
dataManager.commit(foo, bar);