I am getting javax.persistence.EntityNotFoundException error when I am trying to get User through Invoice object
invoice.getUser().getId()
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.
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.
Use @NotFound(action = NotFoundAction.IGNORE) in case it's parent not exist
By using cascade=CascadeType.ALL it will delete it's parent entity
I had the same problem, and
@NotFound(action = NotFoundAction.IGNORE)
solved my problem.
please try the following
@OneToMany(mappedBy="yourMappingattributeName",cascade=CascadeType.ALL)
or
@OneToMany(mappedBy="yourMappingattributeName",cascade=CascadeType.MERGE)
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.