javax.persistence.EntityNotFoundException: Unable to find报错

Posted nicknailo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javax.persistence.EntityNotFoundException: Unable to find报错相关的知识,希望对你有一定的参考价值。

  这类错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.或者跟业务人员联系,看数据模拟有问题,直接干掉吧




以上是关于javax.persistence.EntityNotFoundException: Unable to find报错的主要内容,如果未能解决你的问题,请参考以下文章