-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with XML persistence for polymorphic associations
PostPosted: Tue Mar 14, 2006 11:20 am 
Newbie

Joined: Tue Mar 07, 2006 5:57 am
Posts: 1
Location: Manchester, UK
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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.