I get the following error when attempting to persist an object:
java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST
Is there any simple way to tell which relationship has the problem object?
It is possible that the persisted object has many relationships and a trial and error or find by elimination works, but I would like to know if there is a simpler quicker way to identify the problem relationship object.
Update: I encounter this problem periodically, and I have always been able to find the source of the problem, or have been able to reorder the operations in order to solve the problem, but my issue is the amount of time that it takes to find the offending object.
My solutions have always been found by trial and error. I sometimes find the solution in minutes, but sometimes it takes hours. My question is: is there an easier way to find which of possibly many relationships is causing the problem. The exception only claims that a "new object" was found through a "relationship", this does not help me to find which object or which relationship. Is there a log or a way to tell the system to provide a more specific error?
The next is a listener for all the request of your APP, to activate it :
In your persistence.xml
add:
<property name="eclipselink.session.customizer" value="dz.bilelovitch.QueryListener"/>
Create the QueryListener
:
import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.sessions.Session;
public class QueryListener implements SessionCustomizer {
@Override
public void customize(Session aSession) throws Exception {
System.out.println("log " + aSession.getLog() );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With