春/休眠数据库之间切换
问题描述:
在我的项目中,我使用Spring和hibernate。我使用MySql并为Ids使用自动增量。但现在我需要支持多种数据库类型。 (单独安装)。说,MySql,Oracle(11g),Postgresql等春/休眠数据库之间切换
我目前的想法是使用uuid主键,因为我可以切换到任何数据库,而不必担心数据库层。但因为我已经使用Integer作为auto_increment,所以我必须修改我的代码库。
有没有办法保留Integer ID?还是应该继续使用uuid?
当前实现
@Id
@GeneratedValue
@Column(name = "id", nullable = false, updatable = false)
private Integer id;
还是这个(或任何其他解决方案)
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column
@Id
private String id;
答
我找到了一种方法来做到这一点。
想法是添加注释配置并使用xml覆盖它。
XML metadata may be used as an alternative to these annotations, or to override or augment annotations
这里是一个很好的教程,