I am getting javax.persistence.EntityNotFoundException error when I am trying to get User through Invoice object
invoice.getUser().getId()
If you use @ManyToOne, the referenced entity must exist. The only other option is to specify that field as a long and retrieve the referenced entity by means of a separate query.
Throws an exception (javax.persistence.EntityNotFoundException) instead of returning null if it can't find the requested entity.
Use @NotFound annotation to resolve this exception if you are lazy loading and not handling this exception manually.
@ManyToOne(
fetch = FetchType.LAZY)
@NotFound(
action = NotFoundAction.IGNORE)
@JoinColumn(
name = COLUMN,
referencedColumnName = COLUMN,
insertable = false,
updatable = false)
private Table table;