【发布时间】:2015-10-11 19:16:51
【问题描述】:
我在我的 Spring MVC 项目中使用休眠和 MySQL 数据库。我使用@GeneratedValue 注释在我的 id 字段上设置自动增量。所以我所有的实体都有这段代码,一切都按预期工作:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
此时,我想切换到 Oracle 数据库。现在,我有两个问题:
1. 在 oracle 中设置自增字段的最佳解决方案是什么?我使用了此代码,但无法正常工作:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_Sequence")
@SequenceGenerator(name="id_Sequence", allocationSize=1)
2(更重要的问题)。有没有办法使用一个独特的注释来设置适用于 MySQL 和 Oracle 的自动增量?
【问题讨论】:
标签: java mysql oracle hibernate auto-increment