I’m inserting multiple records to MySQL with Hibernate 5.
After a constraint failure, all the records are failed to get inserted with the error ‘org.hibernate.AssertionFailure: null id in entry (don’t flush the Session after an exception occurs)’. To get rid of this problem, I cleared the hibernate session when the exception occurs with session.clear().
Data is getting pumped without any problem now.

no it won’t work always , hibernate is unable to create auto generated ID