-->
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.  [ 2 posts ] 
Author Message
 Post subject: Polymorphic One-To-Many times 2
PostPosted: Wed Jun 01, 2005 8:20 am 
Newbie

Joined: Wed Jun 01, 2005 8:04 am
Posts: 2
If this has been answered, pls post link as I've done my searches and gone through the manuals.

I wonder if this is possible to map:

Class Activity points to a collection of Address subclasses twice, e.g. Activity has two Sets: one for internalAddresses one for externalAddresses each of which contain a set of Address subclasses.

I was hoping to use "Table per Concrete class" inheritance mapping, but I'm coming unstuck because I've got two arrays to populate on Activity. I keep getting :

net.sf.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: com.simon.dao.InternalAddressesDo (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:455)

Please advise if how I should approach this, as I've tried using polymorphism, discriminator-value attributes, but seem to always hit a wall because of the two foreign keys.

Thanks


Top
 Profile  
 
 Post subject: Solution
PostPosted: Thu Jun 02, 2005 2:13 am 
Newbie

Joined: Wed Jun 01, 2005 8:04 am
Posts: 2
I solved it. FYI:

I needed to add the 'discriminator-value' on the subclass element on the many side hbm.xml as well as a 'where' attribute on the parent mapping. (It's the parent side that I kept missing)

Child:

<class name="com.simon.dao.AddressDo" table="ADDRESS">

<id name="id" column="UID" type="long" unsaved-value="0">
<generator class="increment"/>
</id>
<discriminator type="string" column="type"/>
<property name="displayName" column="DisplayName" not-null="true" />
<property name="emailAddress" column="EmailAddress" not-null="true" />
<property name="firstName" column="FIRSTNAME" not-null="true"/>
<property name="lastName" column="LASTNAME" not-null="true"/>
<many-to-one class="com.simon.dao.ActivityDo"
name="activity"
column="activity_id"
/>
<subclass name="com.simon.dao.InternalParticipantDo" discriminator-value="INT" >
</subclass>
<subclass name="com.simon.dao.ExternalParticipantDo" discriminator-value="EXT">
</subclass>

</class>

PARENT:

<class name="com.simon.dao.ActivityDo" table="ACTIVITY" >
<id name="id" column="UID" type="long" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="value" column="value" not-null="false"/>

<set name="internalCCParties" cascade="all" inverse="true" where="type='INT'">
<key column="activity_id"/>
<one-to-many class="com.simon.dao.InternalParticipantDo"/>
</set>

<set name="safParticipants" cascade="all" inverse="true" where="type='EXT'">
<key column="activity_id"/>
<one-to-many class="com.simon.dao.ExternalParticipantDo"/>
</set>

</class>


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.