简体   繁体   English

当我的表的PK是身份时如何插入对象Hibernate(JPA)(sql server)

[英]How insert object Hibernate(JPA) when PK of my table is identity (sql server)

This is my Object that represent my table:这是代表我的表的对象:

@Entity
@Getter
@Setter
@EqualsAndHashCode
@ToString
public class Motivo {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long codigomotivo;
    private String descricaomotivo;
    private Integer codrubricadominio;
    private String tipo;

}

My column codigomotivo in database is identity , she autoincrement values.我在数据库中的codigomotivo列是identity ,她自动递增值。 In this form, i receive error:在这种形式中,我收到错误:

com.microsoft.sqlserver.jdbc.SQLServerException: DEFAULT or NULL are not allowed as explicit identity values. com.microsoft.sqlserver.jdbc.SQLServerException:不允许将 DEFAULT 或 NULL 作为显式标识值。

this is a insert that hibernate generate in log:这是休眠在日志中生成的插入:

Hibernate: insert into Motivo (codigomotivo, codrubricadominio, descricaomotivo, tipo) values (null, ?, ?, ?)

I Have tried too @GeneratedValue(strategy = GenerationType.AUTO) and receive this message in log:我也尝试过@GeneratedValue(strategy = GenerationType.AUTO)并在日志中收到此消息:

Hibernate: call next value for hibernate_sequence com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'value' Hibernate:调用 hibernate_sequence com.microsoft.sqlserver.jdbc.SQLServerException 的下一个值:“值”附近的语法不正确

And too only @GeneratedValue and receive same error above.而且也只有@GeneratedValue并收到上面相同的错误。

How i can insert values in my table in this configuration PK in Sql Server ?如何在Sql Server的此配置 PK 中的表中插入值?

只需将您的方言更改为:

org.hibernate.dialect.SQLServerDialect 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate 1.0 + JPA + Netbeans 7.01 + SQL Server 2005 =使用GenerationType.IDENTITY插入表中的问题 - Hibernate 1.0 + JPA + Netbeans 7.01 + Sql server 2005 = Problems to insert into table with GenerationType.IDENTITY JPA:如何将PK设置为MAX(PK)+ 1 - JPA: How to INSERT setting PK to MAX(PK) + 1 在SQL Server表上设置IDENTITY_INSERT时出错 - Error when setting IDENTITY_INSERT on sql server table 当嵌入的键包含 SQL Server 上的标识列时,休眠插入失败 - Hibernate insert failing when embedded key contains identity column on SQL Server JPA Hibernate删除实体的子对象,与双PK连接触发SQL更新而不是删除? - JPA Hibernate remove child object of entity, connected with dual PK triggers SQL update instead of delete? JPA / Hibernate OneToOne与相同PK的双向关系错误的插入顺序 - Wrong insert order at JPA/Hibernate OneToOne bidirectional relationship with the same PK 如何仅插入连接表而不插入 JPA Hibernate 中的引用表 - How to insert only in join table but not in reference table in JPA Hibernate 持久化Hibernate / JPA,其中对象标识很重要 - Persistence with Hibernate/JPA where object identity is important JPA 2.0(Hibernate)使用@JoinTable为@OneToMany生成了不正确的联接表PK - JPA 2.0 (Hibernate) generates incorrect join table PK for @OneToMany with @JoinTable 使用带注释的JPA对象(Hibernate JPA提供程序)时,如何在列中插入MySQL表的默认日期时间值? - How do I insert MySQL table's default datetime value in a column when using annotated JPA objects (Hibernate JPA provider)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM