Bypass "Entity not found" error with JPA

No, at least nothing standard (JPA)

But you can control what happens with these association using the cascade attribute ot @*ToMany and @*ToOne annotations.


You can use the @NotFound annotation with the value NotFoundAction.IGNORE, which will return null if an associated entity doesn't exist.

A word of caution: if you use this in a collections and hibernate doesn't find one of the entries, it will add a null value in the collection, which is very annoying. To avoid this, you can wrap the collection in a Collection that skips nulls.

Tags:

Hibernate

Jpa