我对User
表有一对一的关系,如下所示
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@JoinColumn(name = "userFakeInfo", referencedColumnName = "id")
private UserFakeInfo userFakeInfo;
和子表是
@Entity
public class UserFakeInfo {
public enum FlagReason {
CELEBRITY, QUARANTINE, INCENTIVE, FAILED_FACE_DETECTION, GOOGLE_IMAGE_CHECK_FAILED, SILVER_SPARRO_IMAGE_CHECK_FAILED, PAID_FUN_CONTENT_IN_PQ, PAID_FUN_CONTENT_IN_QUESTION, PAID_FUN_CONTENT_IN_ANSWER, PAID_FUN_CONTENT_FOUND_IN_CHAT, SUSPICIOUS_MULTIPLE_LIKE_FROM_PFG, PFG_FLAG_THROUGH_CP, PFG_FLAG_BY_OPS
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
private FlagReason flagReason;
private String curationStatus;
private Date createdTime;
private Date updatedTime;
@PrePersist
protected void updateDates() {
if (createdTime == null) {
createdTime = new Date();
}
updatedTime = new Date();
}
@PreUpdate
protected void update() {
updatedTime = new Date();
}
然后是getter和setter。
我正在尝试根据某些逻辑更新子表,但每次都失败。虽然updatedTime正在更新,但其他两个字段没有得到更新。
@Override
@Transactional
public void updateCurationStatus(User user, String curationStatus, UserFakeInfo fakeInfo) {
fakeInfo.setCurationStatus(curationStatus);
checkAndApplyPFGMatchFlagging(user, curationStatus, fakeInfo);
user.setUserFakeInfo(fakeInfo);
userRepository.save(user);
}
private void checkAndApplyPFGMatchFlagging(User user, String curationStatus, UserFakeInfo fakeInfo) {
if (isToFlagMatches(user, curationStatus)) {
LOGGER.info("User={} is a PFG user, her all matches will be flagged", user.getId());
fakeInfo.setFlagReason(FlagReason.PFG_FLAG_THROUGH_CP);
} else if (isToUnFlagMatches(user, curationStatus)) {
LOGGER.info("User={} is not a PFG user, her all matches will be un-flagged", user.getId());
fakeInfo.setFlagReason(null);
}
}
任何帮助将不胜感激。