Is there a reasonable way to get the generated id of a transient child?
I have a parent entity (P1) with a bidirectional one-to-many collection of children, and I create a new child (C1) and add it to the empty collection (setting its bidirectional link to P1) and save the parent (P1), I now have a parent with a collection of children that have IDs, but the object I started with (C1) isn’t in the collection, a new object (C2) has taken its place with the same values, and that object has the newly generated id.
So if I retain a reference to the child, that child reference still points to C1, which doesn’t have a generated id. Because the collection is a list and I’m using @OrderColumn, I should be able to use the list index to retrieve C2 and get the identifier that way. I could also compare the values if the collection weren’t ordered, but that would be a pain.
Why is Hibernate replacing C1 with C2? Is it something about the entities or the mappings?