Reputation: 31
I am using Hibernate over SQL Server for a web application. I was using the "increment" generator class till now and recently ran into ConstraintViolation exceptions.
So, I changed the generator to "identity" and I am getting the following error -
Cannot insert the value NULL into column 'assessment_administration_id', table 'faip.dbo.assessment_administration'; column does not allow nulls. INSERT fails.
Following is the mapping -
<class name="AssessmentAdministration" table="assessment_administration">
<id name="id" type="long" column="assessment_administration_id">
<generator class="identity" />
</id>
<property name="administrationName" column="administration_name" />
</class>
What am I doing wrong here? I looked at this post http://www.coderanch.com/t/216051/ORM/java/Hibernate-MSSQL-identity-column, but the solution is not posted.
Upvotes: 3
Views: 7408
Reputation: 570385
Is your ID
column actually an IDENTITY
column? If it isn't, then that's your problem since Hibernate won't include the ID column in an insert statement when using an identity
generator, relying on the database to generate the value. Did you alter the table after changing the generator strategy?
Upvotes: 3