在进行一对多关系时,我无法更新子对象。 当我要更新记录时,收到“正在合并同一实体[com.aexp.grt.publisher.model.ExternalSource#163]的多个表示”消息。
ExternalSource.java:
you cant solve this relation with akra-bazzi method because 2^n is not polynomial .
But for solving with finding bounds :
it's obvious that:
1) T(n) >= 2^n (cause we can see in the relation we have 2^n and other things :)) )
and we know that the :
2) T(n) <= 4T(n/2) + 2^n . and we can solve this with master method and the answer of 4t(n/2) + 2^n is θ(2^n) .
1+2) now we have this : θ(2^n) <= T(n) <= 2^n .
so we have the answer :
T(n) ∈ θ(2^n).
ExternalSourceExecution.java:
@Entity
@Table(name="external_src")
public class ExternalSource extends AbstractEntity implements Serializable{
// Variables --------------------------------------------------------Starts
private static final long serialVersionUID = 6856225421019089955L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "external_src_id",unique = true, nullable = false)//external_src_id
private int externalSrcId;
@Column(name = "target_table")
private String targetTable;
@Column(name = "target_database")
private String targetDatabase;
@Column(name = "target_usecase")
private String targetUsecase;
@JsonManagedReference
@OneToMany(mappedBy = "externalSource",fetch = FetchType.EAGER,orphanRemoval = true)
@Cascade({CascadeType.ALL})
private List<ExternalSourceExecution> externalSourceExecution;
// Variables --------------------------------------------------------Ends
// Getter Setter -------------------
}
控制器类更新方法():
@Entity
@Table(name="external_src_exec")
public class ExternalSourceExecution extends AbstractEntity implements Serializable {
// Variables --------------------------------------------------------Starts
private static final long serialVersionUID = -562117894266007656L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "external_src_exec_id")
private int externalSrcExecId;
@Column(name="status")
private String status;
@Column(name="last_refresh")
public Timestamp lastRefresh;
@JsonBackReference
@ManyToOne(targetEntity=ExternalSource.class,fetch = FetchType.EAGER)
@JoinColumn(name = "external_src_id")
@Cascade({CascadeType.ALL})
private ExternalSource externalSource;
// Variables --------------------------------------------------------Ends
// Getter Setter ---------------------------------------Starts
}
邮递员要求:
@PutMapping("/updateExternalsources")
public ResponseEntity<ExternalSource> update(@RequestBody ExternalSource externalSource) {
ExternalSource externalSourceOld = null;
try{
externalSourceOld= externalSourceService.findExternalSourceById(externalSource.getExternalSrcId());
if(externalSourceOld==null){
int externalSourceId = externalSource.getExternalSrcId();
externalSource.setExternalSrcId(externalSourceId);
log.error("Id " + externalSourceId + " is not existed");
ResponseEntity.badRequest().build();
}else{
externalSourceOld.setSourceName(externalSource.getSourceName());
externalSourceOld.setSourceType(externalSource.getSourceType());
externalSourceOld.setConnectionDetails(externalSource.getConnectionDetails());
externalSourceOld.setExtractionDetails(externalSource.getExtractionDetails());
externalSourceOld.setTargetTable(externalSource.getTargetTable());
externalSourceOld.setTargetDatabase(externalSource.getTargetDatabase());
externalSourceOld.setTargetUsecase(externalSource.getTargetUsecase());
externalSourceOld.setModifiedBy(externalSource.getModifiedBy());
externalSourceOld.setModifiedDate(externalSource.getModifiedDate());
externalSourceOld.setExternalSourceExecution(null);
externalSourceOld.setExternalSourceExecution(externalSource.getExternalSourceExecution());
}
}catch(Exception e){
}
return ResponseEntity.ok(externalSourceService.createExternalSource(externalSourceOld));
}
错误:
{
"externalSrcId":163,
"sourceName": "Updated",
"sourceType": "Updated",
"connectionDetails": "Updated",
"extractionDetails": "Updated",
"targetTable": "Updated",
"targetDatabase": "Updated",
"targetUsecase": "Updated",
"createdBy": 1513295789000,
"createdDate": 1513295789000,
"modifiedBy": 1513295789000,
"modifiedDate": 1513295789000,
"externalSourceExecution":[
{
"status": "Updated",
"lastRefresh": 1513295789000,
"createdBy": 1513295789000,
"createdDate": 1513295789000,
"modifiedBy": "Pankaj Dagar",
"modifiedDate": 1513295789000
}
]
}