开发者

Hibernate exception while using "identity" generator - how to use

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开发者_如何学Go 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜