GraphQL Spring Boot: Parent field retrieve null id wrongly

Viewed 37

I have an "Organization" class that has "Organization parent" field. It's fetch type is lazy and relation is Many-To-One;

@Entity
@Table(name = "organization", uniqueConstraints = {@UniqueConstraint(columnNames = {"name", 
"code"})})
public class Organization extends BaseDomain {

private String name;
private String baseUrlBackend;
private String baseUrlFrontend;
private String code;
private Organization parent;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
public Organization getParent() {
    return parent;
}

. . . when i am trying to get organization with it's id i'm getting this error;

enter image description here

as i can understand i am having this trouble because; "Organization parent" is nullable but an "Organization" class has to have an "id" value. But if there is no parent, there can't be any id value neither. Is there an annotation or config file to solve that problem.

So far i tried some solutions. When i change the FetchType.LAZY to FetchType.EAGER problem is solved but i don't want to change the FetchType so im looking for different solutions.

0 Answers
Related