How solve javax.persistence.EntityNotFoundException with JPA (not by using @NotFound)

后端 未结 6 850
悲哀的现实
悲哀的现实 2021-02-05 10:28

We are using JPA to load some stuff from a database. Some entities may have optional relationships between them, e.g.

@Entity
public class First {
    ....
    @         


        
6条回答
  •  情深已故
    2021-02-05 10:58

    What about adding a test in the correspondent entity class:

    public boolean getHasSecond() {
        if (this.Second != null) {
            return true;
        } else {
            return false;
        }
    }
    

    Like this, you can check if the relation exists...

提交回复
热议问题