views:

19

answers:

0

I have two objects, A and B. They both share the same types of fields, 1 and 2. Their relationship can be expressed in SQL as follows:

A's Bs: SELECT * FROM B WHERE B.1 = A.1 AND (B.2 = A.2 OR B.2 IS NULL)

B's As: SELECT * FROM A WHERE B.1 = A.1 AND (A.2 = B.2 OR B.2 IS NULL)

That's the tricky part - that B.2 can be null and still be considered a match for A, as long as the first property matches.

I'm unsure of how to map this relationship in JDO. I suppose I could just do a query and stuff the objects into a transient collection in the objects, but I'd really like it to be mapped for me. If it matters, DataNucleus is the implementation of JDO. Also, I don't have control of the schema I'm importing, but I do have design of the schema I'm importing it into, so if I should add a table or whatnot, I can do that with the new schema.

I'd prefer any answers to use annotations, but I could probably figure out the appropriate annotations from any provided XML.

So...anyone know how to do this?

related questions