Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在spring boot应用程序中动态设置hibernate@GeneratedValue策略?_Hibernate_Jpa_Spring Boot_Hibernate Annotations - Fatal编程技术网

如何在spring boot应用程序中动态设置hibernate@GeneratedValue策略?

如何在spring boot应用程序中动态设置hibernate@GeneratedValue策略?,hibernate,jpa,spring-boot,hibernate-annotations,Hibernate,Jpa,Spring Boot,Hibernate Annotations,我有一个SpringBoot应用程序,应该在开发环境中的mysql上运行,在生产环境中的SQLServer上运行。 所以我想在应用程序使用prod配置文件运行时设置@GeneratedValue(strategy=GenerationType.IDENTITY),在应用程序使用dev配置文件运行时设置为@GeneratedValue(strategy=GenerationType.AUTO) 我有一个BaseEntity类,所有的实体都是从它扩展而来的: @MappedSuperclass pu

我有一个SpringBoot应用程序,应该在开发环境中的mysql上运行,在生产环境中的SQLServer上运行。 所以我想在应用程序使用
prod
配置文件运行时设置
@GeneratedValue(strategy=GenerationType.IDENTITY)
,在应用程序使用
dev
配置文件运行时设置为
@GeneratedValue(strategy=GenerationType.AUTO)

我有一个
BaseEntity
类,所有的实体都是从它扩展而来的:

@MappedSuperclass
public abstract class BaseEntity<T> implements Serializable {

    @Id
    @Column(name = "id", unique = true, nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO) // how to chagne this dynamically?
    private T id;

}
@MappedSuperclass
公共抽象类BaseEntity实现了可序列化{
@身份证
@列(name=“id”,unique=true,nullable=false)
@GeneratedValue(strategy=GenerationType.AUTO)//如何动态更改它?
私人T-id;
}
那么我如何实现这个要求呢?我应该更改
.yml
文件还是实现一些类和更改一些配置来实现这个目标

更新


我不想对SQL Server和MYSQL都使用
sequence
,我想使用SQL Server的
identity
功能,并在MYSQL中使用sequence。

可能重复No,请检查我的更新这是不可能的