Hiberate问题,jdbc IDENTITY_INSERT设置为OFF [英] Hiberate problems, jdbc IDENTITY_INSERT is set to OFF
问题描述
无法在表'中插入标识列的显式值'报告'当IDENTITY_INSERT设置为OFF
我使用由netbeans生成的映射,它包含
< class name =orm.generated.Reporttable =Reportschema =dbocatalog =DatabaseName>
< id name =idtype =int>
< column name =ID/>
< generator class =assigned/>
< / id>
在我看来,它应该正确地插入身份。
关于如何解决这个问题的任何想法?
编辑:
一些指向后代的文档的链接
http://www.hibernate.org/hib_docs/v3/reference/en-US/html/mapping.html#mapping-declaration-id-generator
http://www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml
- 选择一个不同的生成器类,例如native
- Set IDENTITY_INSERT为开
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:
- Pick a different generator class, such as "native"
- Set IDENTITY_INSERT to "ON"
这篇关于Hiberate问题,jdbc IDENTITY_INSERT设置为OFF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!