As far as I understand Hibernate is generating INSERT string in a method: org.hibernate.persister.entity.AbstractEntityPersister::generateInsertString SQL Server JDBC driver is preparing column metadata in: com.microsoft.sqlserver.jdbc.SQLServerBulkBatchInsertRecord::addColumnMetadataInternal And calls it in com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement::executeBatch when trying to perform BULK INSERT :  Problem is that method com.microsoft.sqlserver.jdbc.SQLServerBulkBatchInsertRecord::getRowData is creating BULK INSERT statement by mapping column metadata to Hibernate query by index of the fields and not by names. But as the order of both libraries is inconsistent it doesn’t find anything returns mostly nulls:  (This picture is the most important point of this bug) Process than crashes with Caused by: java.sql.BatchUpdateException: Cannot insert the value NULL into column 'XXX', table 'YYY'; column does not allow nulls. INSERT fails. Full stack-trace starting in our code when flush is called:
Expectation: As AbstractEntityPersister already contains comments and code specially preparing statements for Oracle as there are comments like this:
I’d expect Hibernate to be able to also prepare query which is usable by SQL Server when using BULK INSERT |