Hiberate问题,jdbc IDENTITY

编程入门 行业动态 更新时间:2024-10-25 03:23:26
本文介绍了Hiberate问题,jdbc IDENTITY_INSERT设置为OFF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

无法在表'中插入标识列的显式值'报告'当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可以直接将该值插入到数据库中。您需要:

  • 选择一个不同的生成器类,例如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, 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:

  • Pick a different generator class, such as "native"
  • Set IDENTITY_INSERT to "ON"
  • 更多推荐

    Hiberate问题,jdbc IDENTITY

    本文发布于:2023-10-22 08:31:53,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Hiberate   jdbc   IDENTITY

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!