I am getting JDBC error when I attempt a commit through hibernate to SQL Server
Cannot insert explicit value for identity column in table ‘Report’ when IDENTITY_INSERT is set to OFF
I am using mappings generated by netbeans that contain,
<class name='orm.generated.Report' table='Report' schema='dbo' catalog='DatabaseName'> <id name='id' type='int'> <column name='ID' /> <generator class='assigned' /> </id>
Which looks to me like it should be doing the identity insert properly.
Any idea on how to fix this?
EDIT:
Some links to documentation, for posterity,
http://www.hibernate.org/hib_docs/v3/reference/en-US/html/mapping.html#mapping-declaration-id-generator
http://www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml
You cannot insert into an identity column in SQL Server unless ‘IDENTITY_INSERT’ is set to ‘ON’. Since your generator class is ‘assigned’, Hibernate is assuming that you are setting an explicit value for ‘id’ in Java before saving the object and that Hibernate can directly insert the value into the database. You need to either: