Is there a preferred ordering of defining mapping specifications in a mapping file?
Well, our ORM products (JDX for Java, JDXA for Android, and NJDX for .NET) can deal with mapping specifications of various classes made in any order by making multiple passes, if needed, to parse a specification that might have cross-references. However, to help in understanding, maintaining, and evolving a mapping specification more easily, here are some guidelines:
- Declare the mapping specification of an ELEMENT_CLASS (A) before declaring the mapping specification of a COLLECTION_CLASS (B) or a JOIN_COLLECTION_CLASS (C) involving that ELEMENT_CLASS (A).
- Declare the mapping specification of a JOIN_CLASS (P) before declaring the mapping specification of a JOIN_COLLECTION_CLASS (Q) involving that JOIN_CLASS (P).
- Declare the mapping specification of a referenced class (X) before declaring the mapping specification of a class (Y) referencing that class (X) using the REFERENCES keyword in a RELATIONSHIP specification. The referenced class (X) may be a normal CLASS or a COLLECTION_CLASS or a JOIN_COLLECTION_CLASS. This may not always be possible if there are cross-referencing relationships but that is OK; JDX can handle that unavoidable ordering.
Essentially, try to declare something before using it.