Anonymous
Обновления дочерней таблицы не происходят с помощью fetchType как Lazy
Сообщение
Anonymous » 08 июл 2024, 14:22
Я только что обновился с версии Spring Boot с 2.7.9 до 2.7.10, но обнаружил необычное поведение: обновления дочерней таблицы в pojo ниже не происходят: -
Код: Выделить всё
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@RemoteResource("/cloudSite")
@Table(name = "cloud_sites")
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
public class CloudSite implements Serializable {
private static final long serialVersionUID = 4701261544750504567L;
@JsonProperty
@BusinessKey
@Id
@Column(name = "ID")
private String id;
@JsonProperty("region_id")
@BusinessKey
@Column(name = "REGION_ID")
private String regionId;
@JsonProperty("aic_version")
@BusinessKey
@Column(name = "CLOUD_VERSION")
private String cloudVersion;
@JsonProperty("clli")
@BusinessKey
@Column(name = "CLLI")
private String clli;
@JsonProperty("platform")
@BusinessKey
@Column(name = "PLATFORM")
private String platform;
@JsonProperty("orchestrator")
@BusinessKey
@Column(name = "ORCHESTRATOR")
private String orchestrator;
@JsonProperty("cloudify_id")
@BusinessKey
@Column(name = "CLOUDIFY_ID")
private String cloudifyId;
@JsonProperty("cloud_owner")
@BusinessKey
@Column(name = "CLOUD_OWNER")
private String cloudOwner;
// Derived property (set by CloudConfig loader based on identityServiceId)
@BusinessKey
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "identity_service_id")
private CloudIdentity identityService;
@BusinessKey
@JsonProperty("identity_service_id")
private transient String identityServiceId;
@JsonProperty("last_updated_by")
@BusinessKey
@Column(name = "LAST_UPDATED_BY")
private String lastUpdatedBy;
@JsonProperty("creation_timestamp")
@BusinessKey
@Column(name = "CREATION_TIMESTAMP", updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@JsonProperty("update_timestamp")
@BusinessKey
@Column(name = "UPDATE_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
private Date updated;
@JsonProperty("support_fabric")
@BusinessKey
@Column(name = "SUPPORT_FABRIC", nullable = false)
private Boolean supportFabric = true;
@JsonProperty("fabric_config_status")
@BusinessKey
@Column(name = "FABRIC_CONFIG_STATUS")
private String fabricConfigStatus;
@Transient
private URI uri;
public CloudSite() {
}
private static final Logger logger = LoggerFactory.getLogger(CloudSite.class);
@PrePersist
protected void onCreate() {
this.created = new Date();
this.updated = new Date();
logger.info("Creating CloudSite: " + this.toString());
}
@PreUpdate
protected void onUpdate() {
this.updated = new Date();
logger.info("Updating CloudSite: " + this.toString());
}
public CloudSite(CloudSite site) {
this.cloudVersion = site.getCloudVersion();
this.clli = site.getClli();
this.id = site.getId();
this.identityService = site.getIdentityService();
this.orchestrator = site.getOrchestrator();
this.platform = site.getPlatform();
this.regionId = site.getRegionId();
this.identityServiceId = site.getIdentityServiceId();
this.supportFabric = site.getSupportFabric();
this.fabricConfigStatus = site.getFabricConfigStatus();
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@ResourceId
public URI getUri() {
return this.uri;
}
public void setUri(URI uri) {
this.uri = uri;
}
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getIdentityServiceId() {
return identityServiceId == null ? (identityService == null ? null : identityService.getId())
: identityServiceId;
}
public String getCloudVersion() {
return cloudVersion;
}
public void setCloudVersion(String cloudVersion) {
this.cloudVersion = cloudVersion;
}
public String getClli() {
return clli;
}
public void setClli(String clli) {
this.clli = clli;
}
public String getCloudifyId() {
return cloudifyId;
}
public void setCloudifyId(String cloudifyId) {
this.cloudifyId = cloudifyId;
}
public String getLastUpdatedBy() {
return lastUpdatedBy;
}
public Date getCreated() {
return created;
}
public Date getUpdated() {
return updated;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
public void setCreated(Date created) {
this.created = created;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getOrchestrator() {
return orchestrator;
}
public void setOrchestrator(String orchestrator) {
this.orchestrator = orchestrator;
}
public CloudIdentity getIdentityService() {
return identityService;
}
public void setIdentityService(CloudIdentity identity) {
this.identityService = identity;
}
public Boolean getSupportFabric() {
return supportFabric;
}
public void setSupportFabric(Boolean supportFabric) {
this.supportFabric = supportFabric;
}
@Deprecated
public void setIdentityServiceId(String identityServiceId) {
this.identityServiceId = identityServiceId;
}
public String getCloudOwner() {
return cloudOwner;
}
public void setCloudOwner(String cloudOwner) {
this.cloudOwner = cloudOwner;
}
public String getFabricConfigStatus() {
return fabricConfigStatus;
}
public void setFabricConfigStatus(String fabricConfigStatus) {
this.fabricConfigStatus = fabricConfigStatus;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("regionId", getRegionId())
.append("identityServiceId", getIdentityServiceId()).append("cloudVersion", getCloudVersion())
.append("clli", getClli()).append("cloudifyId", getCloudifyId()).append("platform", getPlatform())
.append("orchestrator", getOrchestrator()).append("cloud-owner", getCloudOwner()).toString();
}
@Override
public boolean equals(final Object other) {
if (other == null) {
return false;
}
if (!getClass().equals(other.getClass())) {
return false;
}
CloudSite castOther = (CloudSite) other;
return new EqualsBuilder().append(getRegionId(), castOther.getRegionId())
.append(getIdentityServiceId(), castOther.getIdentityServiceId())
.append(getCloudVersion(), castOther.getCloudVersion()).append(getClli(), castOther.getClli())
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion())
.append(getClli()).toHashCode();
}
}
Вывод обновления содержит: -
"identityService": {
"id": "MTKEYSTONE",
"
hibernateLazyInitializer >": {},
"identity_url": "
http://mso-citrus-simulator-svc:10000/sim/v2.0 ",
"mso_id": "m08699",
"mso_pass": "cPSkmcHVb4FPihlDW2viuAXT8AFgLKbys72bz4z2GhQE4NA=",
Если я изменю fetchType на Eager, все будет работать нормально. До загрузки Spring 2.7.9 проблем нет.
Подробнее здесь:
https://stackoverflow.com/questions/787 ... pe-as-lazy
1720437727
Anonymous
Я только что обновился с версии Spring Boot с 2.7.9 до 2.7.10, но обнаружил необычное поведение: обновления дочерней таблицы в pojo ниже не происходят: - [code]@JsonIgnoreProperties(ignoreUnknown = true) @Entity @RemoteResource("/cloudSite") @Table(name = "cloud_sites") @JsonAutoDetect(fieldVisibility = Visibility.ANY) public class CloudSite implements Serializable { private static final long serialVersionUID = 4701261544750504567L; @JsonProperty @BusinessKey @Id @Column(name = "ID") private String id; @JsonProperty("region_id") @BusinessKey @Column(name = "REGION_ID") private String regionId; @JsonProperty("aic_version") @BusinessKey @Column(name = "CLOUD_VERSION") private String cloudVersion; @JsonProperty("clli") @BusinessKey @Column(name = "CLLI") private String clli; @JsonProperty("platform") @BusinessKey @Column(name = "PLATFORM") private String platform; @JsonProperty("orchestrator") @BusinessKey @Column(name = "ORCHESTRATOR") private String orchestrator; @JsonProperty("cloudify_id") @BusinessKey @Column(name = "CLOUDIFY_ID") private String cloudifyId; @JsonProperty("cloud_owner") @BusinessKey @Column(name = "CLOUD_OWNER") private String cloudOwner; // Derived property (set by CloudConfig loader based on identityServiceId) @BusinessKey @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "identity_service_id") private CloudIdentity identityService; @BusinessKey @JsonProperty("identity_service_id") private transient String identityServiceId; @JsonProperty("last_updated_by") @BusinessKey @Column(name = "LAST_UPDATED_BY") private String lastUpdatedBy; @JsonProperty("creation_timestamp") @BusinessKey @Column(name = "CREATION_TIMESTAMP", updatable = false) @Temporal(TemporalType.TIMESTAMP) private Date created; @JsonProperty("update_timestamp") @BusinessKey @Column(name = "UPDATE_TIMESTAMP") @Temporal(TemporalType.TIMESTAMP) private Date updated; @JsonProperty("support_fabric") @BusinessKey @Column(name = "SUPPORT_FABRIC", nullable = false) private Boolean supportFabric = true; @JsonProperty("fabric_config_status") @BusinessKey @Column(name = "FABRIC_CONFIG_STATUS") private String fabricConfigStatus; @Transient private URI uri; public CloudSite() { } private static final Logger logger = LoggerFactory.getLogger(CloudSite.class); @PrePersist protected void onCreate() { this.created = new Date(); this.updated = new Date(); logger.info("Creating CloudSite: " + this.toString()); } @PreUpdate protected void onUpdate() { this.updated = new Date(); logger.info("Updating CloudSite: " + this.toString()); } public CloudSite(CloudSite site) { this.cloudVersion = site.getCloudVersion(); this.clli = site.getClli(); this.id = site.getId(); this.identityService = site.getIdentityService(); this.orchestrator = site.getOrchestrator(); this.platform = site.getPlatform(); this.regionId = site.getRegionId(); this.identityServiceId = site.getIdentityServiceId(); this.supportFabric = site.getSupportFabric(); this.fabricConfigStatus = site.getFabricConfigStatus(); } public String getId() { return this.id; } public void setId(String id) { this.id = id; } @ResourceId public URI getUri() { return this.uri; } public void setUri(URI uri) { this.uri = uri; } public String getRegionId() { return regionId; } public void setRegionId(String regionId) { this.regionId = regionId; } public String getIdentityServiceId() { return identityServiceId == null ? (identityService == null ? null : identityService.getId()) : identityServiceId; } public String getCloudVersion() { return cloudVersion; } public void setCloudVersion(String cloudVersion) { this.cloudVersion = cloudVersion; } public String getClli() { return clli; } public void setClli(String clli) { this.clli = clli; } public String getCloudifyId() { return cloudifyId; } public void setCloudifyId(String cloudifyId) { this.cloudifyId = cloudifyId; } public String getLastUpdatedBy() { return lastUpdatedBy; } public Date getCreated() { return created; } public Date getUpdated() { return updated; } public void setLastUpdatedBy(String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; } public void setCreated(Date created) { this.created = created; } public void setUpdated(Date updated) { this.updated = updated; } public String getPlatform() { return platform; } public void setPlatform(String platform) { this.platform = platform; } public String getOrchestrator() { return orchestrator; } public void setOrchestrator(String orchestrator) { this.orchestrator = orchestrator; } public CloudIdentity getIdentityService() { return identityService; } public void setIdentityService(CloudIdentity identity) { this.identityService = identity; } public Boolean getSupportFabric() { return supportFabric; } public void setSupportFabric(Boolean supportFabric) { this.supportFabric = supportFabric; } @Deprecated public void setIdentityServiceId(String identityServiceId) { this.identityServiceId = identityServiceId; } public String getCloudOwner() { return cloudOwner; } public void setCloudOwner(String cloudOwner) { this.cloudOwner = cloudOwner; } public String getFabricConfigStatus() { return fabricConfigStatus; } public void setFabricConfigStatus(String fabricConfigStatus) { this.fabricConfigStatus = fabricConfigStatus; } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("regionId", getRegionId()) .append("identityServiceId", getIdentityServiceId()).append("cloudVersion", getCloudVersion()) .append("clli", getClli()).append("cloudifyId", getCloudifyId()).append("platform", getPlatform()) .append("orchestrator", getOrchestrator()).append("cloud-owner", getCloudOwner()).toString(); } @Override public boolean equals(final Object other) { if (other == null) { return false; } if (!getClass().equals(other.getClass())) { return false; } CloudSite castOther = (CloudSite) other; return new EqualsBuilder().append(getRegionId(), castOther.getRegionId()) .append(getIdentityServiceId(), castOther.getIdentityServiceId()) .append(getCloudVersion(), castOther.getCloudVersion()).append(getClli(), castOther.getClli()) .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion()) .append(getClli()).toHashCode(); } } [/code] Вывод обновления содержит: - "identityService": { "id": "MTKEYSTONE", "[b]hibernateLazyInitializer[/b] >": {}, "identity_url": "http://mso-citrus-simulator-svc:10000/sim/v2.0", "mso_id": "m08699", "mso_pass": "cPSkmcHVb4FPihlDW2viuAXT8AFgLKbys72bz4z2GhQE4NA=", Если я изменю fetchType на Eager, все будет работать нормально. До загрузки Spring 2.7.9 проблем нет. Подробнее здесь: [url]https://stackoverflow.com/questions/78720552/updates-on-child-table-do-not-happen-with-fetchtype-as-lazy[/url]