collection not getting filtered to requested subclasses
-------------------------------------------------------
Key: HHH-2126
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2126
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.0.cr4
Reporter: Patrick Moore
=========================
The setup
=========================
I have a class that has two maps defined in it to access MessageEndPointImpl instances.
MessageEndPointImpl and MessageSourcePointImpl are subclasses stored in the same table.
The first map accesses MessageEndPointImpls by their database ids:
<map name="messageEndPointsByEntityKey" inverse="true"
access="field"
cascade="all-delete-orphan">
<key column="BROADCAST_PROVIDER" not-null="true"/>
<map-key type="long" column="ID" />
<one-to-many
class="com.transparentpolitics.core.messagehandling.MessageEndPointImpl"/>
</map>
The second map is to access MessageEndPointImpls by their lookup key which only some
MessageEndPointImpls have:
<map name="messageEndPointsByLookupKey" inverse="true"
access="field"
where="LOOKUPKEY IS NOT NULL">
<key column="BROADCAST_PROVIDER" not-null="true"/>
<map-key type="string" column="LOOKUPKEY" />
<one-to-many
class="com.transparentpolitics.core.messagehandling.MessageEndPointImpl"/>
</map>
=======================
The problem
=======================
Trying to access the MessageEndPointImpls using the second map results in this exception.
It is trying to include in the returned collection, the MessageSourcePointImpls. This is
clearly wrong because the map definition specifies a one-to-many mapping with
MessageEndPointImpl
org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass:
com.transparentpolitics.core.messagehandling.MessageEndPointImpl (loaded object was of
wrong class class com.transparentpolitics.core.messagehandling.MessageSourcePointImpl)
at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1234)
at org.hibernate.loader.Loader.getRow(Loader.java:1186)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1918)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at
org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentMap.values(PersistentMap.java:196)
at
com.transparentpolitics.core.BroadcastProvider.getMessageEndPointSet(BroadcastProvider.java:425)
at
com.transparentpolitics.core.BroadcastProvider.getMessageEndPointsMonitoringTopics(BroadcastProvider.java:491)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:185)
at
com.transparentpolitics.core.BroadcastProvider$$EnhancerByCGLIB$$f7a6748d.getMessageEndPointsMonitoringTopics(<generated>)
==============================
Workaround:
==============================
changing the map definition to explicitly filter on the discriminator-value for
MessageEndPointImpl works.
<map name="messageEndPointsByLookupKey" inverse="true"
access="field"
where="LOOKUPKEY IS NOT NULL AND POINT_TYPE='MEP'">
<key column="BROADCAST_PROVIDER" not-null="true"/>
<map-key type="string" column="LOOKUPKEY" />
<one-to-many
class="com.transparentpolitics.core.messagehandling.MessageEndPointImpl"/>
</map>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira