无法在表'中插入标识列的显式值'报告'当IDENTITY_INSERT设置为OFF
我使用由netbeans生成的映射,它包含 < class name =orm.generated.Reporttable =Reportschema =dbocatalog =DatabaseName> < id name =idtype =int> < column name =ID/> < generator class =assigned/> < / id>
在我看来,它应该正确地插入身份。
关于如何解决这个问题的任何想法?
编辑: 一些指向后代的文档的链接 www.hibernate/hib_docs/v3/reference/en-US/html/mapping.html#mapping-declaration-id-generator www.roseindia/hibernate/hibernateidgeneratorelement.shtml
$ b $除非IDENTITY_INSERT设置为ON,否则无法插入SQL Server中的标识列。由于您的生成器类是分配的,因此Hibernate假定您在保存对象之前为Java中的id设置了明确的值,并且Hibernate可以直接将该值插入到数据库中。您需要:
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, www.hibernate/hib_docs/v3/reference/en-US/html/mapping.html#mapping-declaration-id-generator www.roseindia/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:
更多推荐
Hiberate问题,jdbc IDENTITY
发布评论