Cascading inserts are failing after upgrade
Description
Attachments
Activity
Markus Döring April 23, 2020 at 10:11 AMEdited
I had the same problem (with 4.1.11 and 5.1) and found that this is only occuring when using hbm.xml files.
I changed some of my entites to annotations and the problem is solved.
Parts of my hbm.xml file causing the problem:
Annotated telations with problem solved:
Maybe this helps finding the issue or someone else finding a workaround.
Regards
Markus Döring

Himavanth Rachamsetty April 13, 2016 at 6:25 AMEdited
I just checked this testcase with 5.1.0 and it is failing.
These are the SQLs that hibernate generates.
Hibernate: insert into orders (CustomerID) values
Hibernate: insert into orders (CustomerID) values
Hibernate: insert into customers (CustomerID) values
Hibernate: update orders set CustomerID=? where OrderID=?
Hibernate: update orders set OrderID=? where OrderID=
That last one is the issue.
It fails in MSSQLServer with the error "cannot update identity column OrderID"
Here is the stacktrace again.
ERROR: HHH000346: Error during managed flush [could not execute statement]
org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
at org.hibernate.persister.collection.OneToManyPersister.writeIndex(OneToManyPersister.java:249)
at org.hibernate.persister.collection.OneToManyPersister.recreate(OneToManyPersister.java:171)
at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:468)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3135)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2352)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
at cascadeissue.Main.saveEntities(Main.java:45)
at cascadeissue.Main.main(Main.java:34)
Caused by: java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot update identity column 'OrderID'.
Steve Ebersole October 28, 2015 at 3:25 AM
As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.
Steve Ebersole October 27, 2015 at 7:15 PM
This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.
For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/
I had logged for this but looks like that was closed because of a mis-understanding.
I am using map and map-key as opposed to list and ordercolumn.
I had commented on that bug but didn't get a response.
Cascading inserts are failing in 4.1.12 .
Looks like it is because of https://hibernate.atlassian.net/browse/HHH-5732
Testcase attached.
There is an extra SQL generated in 4.1.12 when compared to 4.1.10
Hibernate: update orders set OrderID=? where OrderID=?