EntityNotFoundException in Hibernate Many To One mapping however data exist

前端 未结 9 1469
庸人自扰
庸人自扰 2020-12-13 12:39

I am getting javax.persistence.EntityNotFoundException error when I am trying to get User through Invoice object

invoice.getUser().getId()

Error is as follo

相关标签:
9条回答
  • 2020-12-13 12:46

    I had the similar issue recently, but the problem is that record is always existed in DB. So I did some investigation, found out that at some point that cached entity is marked as removal and reload failed before reloading from DB. It happened in Hibernate 4.3.5 Final for me Then I upgrade to Hibernate 4.3.11 Final which seems to fix the issue.

    0 讨论(0)
  • 2020-12-13 12:47

    Maybe one comes to this answer and finds it useful: In my case, I have marked my entity as deleted and entity who is relationship with this entity could not find it. So, changing deleted to false worked for me.

    0 讨论(0)
  • 2020-12-13 12:50

    Use @NotFound(action = NotFoundAction.IGNORE) in case it's parent not exist

    By using cascade=CascadeType.ALL it will delete it's parent entity

    0 讨论(0)
  • 2020-12-13 12:51

    I had the same problem, and

    @NotFound(action = NotFoundAction.IGNORE)
    

    solved my problem.

    0 讨论(0)
  • please try the following

    @OneToMany(mappedBy="yourMappingattributeName",cascade=CascadeType.ALL) or

    @OneToMany(mappedBy="yourMappingattributeName",cascade=CascadeType.MERGE)
    
    0 讨论(0)
  • 2020-12-13 12:52

    Not sure if that applies to your case.

    But I had a similar issue where I updated directly in the database table X and set a field null, but in java class the field was @NotNull.

    So when another class Y had a X object with ManyToOne, it wasn't able to load the entity because of the null value in the entity.

    0 讨论(0)
提交回复
热议问题