[英]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.