Child ID not assigned by parent

I go through the "Sequence Identification Strategy" and came across the following instruction

The identifier of the child is not assigned to the parent persist.

A common problem is that the generated identifier is part of the identifier of the child through the display of OneToOne or ManyToOne. In this case, because the JPA requires the child to specify a duplicate base mapping for the Identifier, its Identifier will be inserted as null. One solution to this is to mark the column on the identity mapping in the child element insertable=false , updateable=false and define OneToOne or ManyToOne using a regular JoinColumn ensures that the foreign key field is filled by OneToOne or ManyToOne not Basic. Another option is to save the parent first, then call flush () before continuing with it.

Can someone explain what the problem the author is trying to convey to us?

Also I see that insertable=false, updateable=false it looks like we are making the column read-only, is that what attributes mean? Why are we creating a read-only column (without inserting and updating), can you give an example?

0
java hibernate jpa
source share
1 answer

Basically, what the author is trying to say is that in the case of parenting with children, we must first transfer the child and then link the child to the parent and then save the parent or allow the parent to remain in it. This can be done using insertable=false, updateable=false .

What insertable=false, updateable=false means is that the responsibility for creating / updating the corresponding object is not part of the child object. You have a child and a parent. You want to add insertable = false, updatable = false to the @OneToMany relationship with the child in the parent, simply because the responsibility for creating or updating the parent is not responsible for the child. This is the opposite.

+1
source share

All Articles