[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1846) Collection of subclassed objects includes objects with wrong discriminator type

Mathieu Veron (JIRA) noreply at atlassian.com
Tue Aug 8 03:20:19 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1846?page=comments#action_23869 ] 

Mathieu Veron commented on HHH-1846:
------------------------------------

We have the same issue on Hibernate 3.0.5, MySql 4.1.9,
on a very similar mapping,
with a one-to-many default fetch.
In our case a where condition is possible on the set, but is not clean imho.

> Collection of subclassed objects includes objects with wrong discriminator type
> -------------------------------------------------------------------------------
>
>          Key: HHH-1846
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1846
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Versions: 3.1.3
>  Environment: Hibernate 3.1.3, MySQL 4.1.16
>     Reporter: Corey Gerritsen

>
>
> We have a class that has a set of a subclass of another class...
> I.e.,
> MyClass.hbm.xml:
>   <class name="MyClass" table="myclass">
>         ...
>     <set name="mySet" table="my_class_link_some_subclass">
>       <key column="my_class_id"/>
>       <many-to-many column="some_subclass_id" class="SomeSubclass" />
>     </set>
>   </class>
> /MyClass.hbm.xml
> SomeClass.hbm.xml:
>   <class name="SomeClass" table="someclass">
>     <id name="id" column="id" type="long">
>       <generator class="identity"/>
>     </id>
>     <discriminator column="type" type="string" />
>         ...
>     <subclass name="SomeSubclass" discriminator-value="SOMESUBCLASS">
>             ...
>     </subclass>
>     <subclass name="AnotherSubclass" descriminator-value="ANOTHERSUBCLASS">
>             ...
>     </subclass>
>   </class>
> /SomeClass.hbm.xml
> When the many-to-many from MyClass to SomeSubclass is fetch="join" (the default), the Set contains SomeSubclass objects that were initialized by rows with either type='SOMESUBCLASS' or type='ANOTHERSUBCLASS', not only those with type='SOMESUBCLASS'
> This isn't the actual way we found this bug - this also affects caching: we had the collection cached, and when an individual element of the collection expires from the cache, Hibernate tries to reload it by id and descriminator, and can't find elements that shouldn't have been loaded in the first place, throwing, for example, this trace:
> org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [SomeSubclass#42]
>         at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
>         at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:128)
>         at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
>         at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
>         at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
>         at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
>         at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
>         at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
>         at org.hibernate.collection.PersistentSet.initializeFromCache(PersistentSet.java:101)
>         at org.hibernate.cache.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:35)
>         at org.hibernate.event.def.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:130)
>         at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:48)
>         at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
>         at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
>         at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
>         at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
> ...etc. (we were iterating over the Set of SomeSubclass objects)
> Note that when this happens, SomeClass.mySet contains a reference to a SomeSubclass with id 42, the database has a row in someclass with id = 42 and type = 'ANOTHERSUBCLASS'

-- 
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.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list