Hi,
I have a relatively large UML model that has been used primarily for XML Schema design. I'm trying to use Hibernate for creating an API for this model. So far, the XML persistence seems to work really nicely except in the following rare case (that unfortunately is essential for our model):
There is an entity ProtocolCollection 1---->0.* Protocol (association called allProtocols).
Protocol is abstract and has several concrete subclasses, such as GenericProtocol.
I have mapped the inheritence using the "Table per subclass" approach (although I have also tried various other methods automatically generated by AndroMDA).
If I create a new ProtocolCollection and associate it with GenericProtocol - everything is set okay in the database and all objects can be retrieved okay. However, if I try to retrieve it from the database as XML, I get the following output:
<ProtocolCollection id="4">
<_allProtocols>
<ProtocolImpl id="5" identifier="FuGE:GP.1" name="My test protocol" protocolText="Here is my first protocol...">
</ProtocolImpl>
</_allProtocols>
</ProtocolCollection>
So the "GenericProtocol" node is mapped to a "ProtocolImpl" node (which has not been set anywhere in the mapping file).
If I retrieve the GenericProtocol directly, it is output okay:
<GenericProtocol id="5" identifier="FuGE:GP.1" name="My test protocol" protocolText="Here is my first protocol...">
</GenericProtocol>
Excerpts from my mapping file (note all classes are in a hierarchy hence why Protocol is also a "joined-subclass"):
<set name="_allProtocols" order-by="PROTOCOL_COLLECTION_FK" lazy="false" fetch="select" inverse="false" cascade="delete" node="_allProtocols">
<key foreign-key="PROTOCOL_PROTOCOL_COLLECTION_C">
<column name="PROTOCOL_COLLECTION_FK" sql-type="BIGINT"/>
</key>
<one-to-many class="org.andromda.fugom.Domain.Common.Protocol.ProtocolImpl"/>
</set>
<joined-subclass name="org.andromda.fugom.Domain.Common.Protocol.ProtocolImpl" table="PROTOCOL" dynamic-insert="false" dynamic-update="false" abstract="true">
<key foreign-key="PROTOCOLIFKC">
<column name="ID" sql-type="BIGINT"/>
</key>
...
<joined-subclass name="org.andromda.fugom.Domain.Common.Protocol.GenericProtocolImpl" table="GENERIC_PROTOCOL" dynamic-insert="false" dynamic-update="false" abstract="false" node="GenericProtocol">
<key foreign-key="GENERIC_PROTOCOLIFKC">
<column name="ID" sql-type="BIGINT"/>
</key>
I've tried many different combinations of things in the mapping file, such as setting different "node" mappings but none have produced the desired result. I can think of various hacks to get around this problem (such as performing transformations on the XML after it has been output) but I would like to find a formal solution in the hope that reading back in of the XML will work as well.
Many thanks
Andy Jones
[/code]
|