I have the following entity structure (A, B, C, D are entities):
A-> one-to-many B,
A-> one-to-many C,
B-> one-to-many D,
C-> one-to-many D.
I want to persist entity A with hibernate but I am sending it over web service (cyclic references are eliminated). So, on the server I receive parents that “know” about the children and children don’t know about the parents and I need to link everything up again. The problem is that I need to match D with two parents - what was on the client a single D instance, on the server became two instances which have to be merged and D hadn’t been previously persisted so it doesn’t contain unique id that can be matched. I am thinking about two solutions:
1. Call web service twice – in first call persist Ds and then call it to persist A
2. XmlIDRef, and XmlID annotations so I don’t have to merge Ds (jaxb will do the job for me) but in that case client will have to generate unique ids for that fields and I wanted to avoid that.
How should I do it? Am I on the right track?
Btw, I am using hibernate, cxf and jaxb.