這類錯id 可能是10,可能是27,也可能是其他數字
錯誤描述:
javax.persistence.EntityNotFoundException: Unable to find 某個類 with id ?
原因:
無論是@OneToOne 還是@ManyToOne,出現這個原因都是因爲子表(被關聯表)中沒有主表(關聯表)中ID所對應的記錄。
解決辦法:
1. 檢查爲什麼子表中沒有主表中ID對應的記錄
2. 如果子表中沒有主表ID對應的記錄也可以正常加載數據,那麼需要在主表字段上加一個@NotFound Annotation。示例如下:
@OneToOne(optional=true )
@JoinColumn(name="UserId ",insertable=false, updatable=false)
@NotFound(action=NotFoundAction.IGNORE)
private UserId userId;
這樣,當子表中沒找到數據時,主表中對應的field就是null,而不會報錯了。
3.或者跟業務人員聯繫,看數據模擬有問題,直接幹掉吧