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
IDENTITY_INSERT off in SQL Server Once you have turned the IDENTITY_INSERT option OFF, you cannot insert explicit values in the identity column of the table. Also, the value will be set automatically by increment in the identity column if you try to insert a new record.
The set identity_insert command in SQL Server, as the name implies, allows the user to insert explicit values into the identity column of a table.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With