Jin
Jin

Reputation: 55

How can I save the Entity what have a Entity List When Entity List is Null

It's my first question. I hope I can get any hint here to solve my problem.

I use the hibernate for my application. Here is my Code.

public class A {
    @OneToMany(mappedBy = "a", cascade = {CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval = true, fetch = FetchType.LAZY)
    private List<B> bList;
}

public class B{
    @ManyToOne(fech = FetchType.EAGER, optional = false)
    @JoinColumn(name = "b_id", insertable = false, updatable = false)
    private A a;
}

And I expected that I can save the bList when I save the A automatically. It works.

But there is a big problem when bList is null. hibernate try to save bList with A, even though bList is null.

So it makes this Error.

ORA-01400: cannot insert NULL into ("MYTEMPTB"."TB_B"."B_ID")

how can I solve it?? Please give me some hint. Thanks.

Upvotes: 1

Views: 191

Answers (0)

Related Questions