![](/img/trans.png)
[英]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.