I try to create relation ( map ) with subclass hierarchy.
Say, I have base ( abstract ) class, I use a field ( "name" ) as map key ( it's unique for all subclass istances )
And I like to have
1. Map of all instances
2. Maps of instances of particular subclass
My mapping is:
( from map side, fixtures is map of abstract base class )
Code:
<map
name="fixtures"
lazy="true"
sort="unsorted"
inverse="false"
cascade="delete"
order-by="name"
>
<key
column="projectid"
/>
<index
column="name"
type="string"
/>
<one-to-many
class="com.infodesire.status.project.impl.FixtureData"
/>
</map>
<map
name="laterals"
lazy="true"
sort="unsorted"
inverse="false"
cascade="none"
order-by="name"
>
<key
column="projectid"
/>
<index
column="name"
type="string"
/>
<one-to-many
class="com.infodesire.status.project.impl.LateralData"
/>
</map>
<map
name="manholes"
lazy="true"
sort="unsorted"
inverse="false"
cascade="none"
order-by="name"
>
<key
column="projectid"
/>
<index
column="name"
type="string"
/>
<one-to-many
class="com.infodesire.status.project.impl.ManholeData"
/>
</map>
<map
name="sewers"
lazy="true"
sort="unsorted"
inverse="false"
cascade="none"
order-by="name"
>
<key
column="projectid"
/>
<index
column="name"
type="string"
/>
<one-to-many
class="com.infodesire.status.project.impl.SewerData"
/>
</map>
And here are subclasses:
Code:
<hibernate-mapping>
<class
name="com.infodesire.status.project.impl.FixtureData"
table="fixture"
polymorphism="implicit"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Integer"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<discriminator
column="type"
type="string"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
<many-to-one
name="project"
class="com.infodesire.status.project.impl.ProjectData"
cascade="none"
outer-join="auto"
update="false"
insert="true"
column="projectid"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-FixtureData.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.infodesire.status.project.impl.LateralData"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="lateral"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-LateralData.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="com.infodesire.status.project.impl.ManholeData"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="manhole"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ManholeData.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="com.infodesire.status.project.impl.SewerData"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="sewer"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SewerData.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
</hibernate-mapping>
Map of parent class ( fixture ) works fine, but whe I try to read map of one of subclasses, I get:
Code:
Failed to lazily initialize a collection: Object with id: 5 was not of the specified subclass: com.infodesire.status.project.impl.SewerData (loaded object was of wrong class)
net.sf.hibernate.WrongClassException: Object with id: 5 was not of the specified subclass: com.infodesire.status.project.impl.SewerData (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:64)
at net.sf.hibernate.collection.Map.size(Map.java:82)
at com.infodesire.status.project.test.FixtureCRUDTest.testFixturesCreation(FixtureCRUDTest.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
r
Question is classical, what I'm doing wrong, or maybe it's unsu