|Re: OneToMany - org.eclipse.persistence.exceptions.DatabaseException [message #1840912 is a reply to message #1838593]
||Wed, 28 April 2021 16:49
| Chris Delahunt
Registered: July 2009
This is old, but thought I might comment:|
The log message you showed "SEVERE: Error while trying to create a child." doesn't seem to fit with the code you've shown, and couldn't come from EclipseLink - it doesn't consider an insert as a create operation (JPA calls it persist, and it uses insert in native code). Seems likely to come from your code in something more specific to Child creation, where maybe it is created with the parent references set to null or maybe even the parent id somehow being null (though I expect something different in that case).
Assuming it is this code, you would need to turn on SQL logging (https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging ) to see the statements it issues within this transaction, to determine if other child inserts are working, if the parent was inserted, or something else is going wrong.
It seems strange that you replace the parent's children collection with an empty one - that shouldn't be necessary, and should really be avoided, as it means this parent entity instance won't reflect what you have in the database when it is done. You might want to call parent.setChildren(children) after the for loop to fix it if you can't just leave the collection there when you call persist on the parent.
Powered by FUDForum
. Page generated in 0.02131 seconds