gpt4 book ai didi

java - 如何在 JPA 中动态更改架构名称

转载 作者:行者123 更新时间:2023-12-02 03:20:58 24 4
gpt4 key购买 nike

我正在使用 JPA 查询 Flyway_schema_history 以打印已执行迁移的报告。 Flyway_schema_history 的结构在我的 Postgresql 数据库中的所有模式中重复。另外,我在运行程序时将架构名称作为参数传递。我使用的是 Java 10。

我在 JPA 中创建了这个实体。

@Entity
@Table(name = "flyway_schema_history", schema="this_should_be dynamic")
public class FlywaySchemaHistoryGeneric {

@Id
@Column(name="installed_rank")
private Integer installedRank;

@Column(name="version")
private String version;

@Column(name="description")
private String description;

@Column(name="type")
private String type;

@Column(name="script")
private String script;

@Column(name="checksum")
private Integer checksum;

@Column(name="installed_by")
private String installedBy;

@Column(name="installed_on")
private Date installedOn;

@Column(name="execution_time")
private Integer executionTime;

@Column(name="success")
private Boolean success;


public Integer getInstalledRank() {
return installedRank;
}

public void setInstalledRank(Integer installedRank) {
this.installedRank = installedRank;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getScript() {
return script;
}

public void setScript(String script) {
this.script = script;
}

public Integer getChecksum() {
return checksum;
}

public void setChecksum(Integer checksum) {
this.checksum = checksum;
}

public String getInstalledBy() {
return installedBy;
}

public void setInstalledBy(String installedBy) {
this.installedBy = installedBy;
}

public Date getInstalledOn() {
return installedOn;
}

public void setInstalledOn(Date installedOn) {
this.installedOn = installedOn;
}

public Integer getExecutionTime() {
return executionTime;
}

public void setExecutionTime(Integer executionTime) {
this.executionTime = executionTime;
}

public Boolean getSuccess() {
return success;
}

public void setSuccess(Boolean success) {
this.success = success;
}
}

我试图使用 FlywaySchemaHistoryGeneric.class.getAnnotation 来更改运行时的值,但没有成功,但我认为这应该是一种简单的方法。如何使 @table 中的模式变得动态?

最佳答案

我猜你无法在运行时修改它,因为注释是只读的。您可以为每个架构创建一个数据源,并选择其中之一来根据您的规则保留实体。

关于java - 如何在 JPA 中动态更改架构名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56926915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com