[英]Hibernate 1.0 + JPA + Netbeans 7.01 + Sql server 2005 = Problems to insert into table with GenerationType.IDENTITY
[英]How insert object Hibernate(JPA) when PK of my table is identity (sql server)
这是代表我的表的对象:
@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;
}
我在数据库中的codigomotivo
列是identity
,她自动递增值。 在这种形式中,我收到错误:
com.microsoft.sqlserver.jdbc.SQLServerException:不允许将 DEFAULT 或 NULL 作为显式标识值。
这是休眠在日志中生成的插入:
Hibernate: insert into Motivo (codigomotivo, codrubricadominio, descricaomotivo, tipo) values (null, ?, ?, ?)
我也尝试过@GeneratedValue(strategy = GenerationType.AUTO)
并在日志中收到此消息:
Hibernate:调用 hibernate_sequence com.microsoft.sqlserver.jdbc.SQLServerException 的下一个值:“值”附近的语法不正确
而且也只有@GeneratedValue
并收到上面相同的错误。
如何在Sql Server
的此配置 PK 中的表中插入值?
只需将您的方言更改为:
org.hibernate.dialect.SQLServerDialect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.