I'm using Hibernate 3.2.6 and I'm experiencing bug
HHH-286. The stack trace received is:
Code:
org.hibernate.HibernateException: collection is not associated with any session
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:449)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:844)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
I'm wondering if there is any way to workaround this bug or whether there is a better way to map my schema in Hibernate. I have the following structure in my (legacy) schema:
Table FOO with column A (key), column B (key), column C (non-key)
Table BAR with column X (key), column Y (key), column Z (key)
I have a one-to-many relationship from FOO (parent) to BAR (child). FOO.A and FOO.C reference BAR.X and BAR.Y. Where FOO.C is null, no child rows exist in BAR.
My problem is that I can have many rows in FOO where FOO.A is some common value and FOO.C is null. For these records there will be no child rows in BAR to be found (because BAR.Y is never null). However the collection key used (the internal key used to lookup Foo.bars) for these rows will then be the same (non-unique) and hence bug HHH-286 occurs.
Is this structure un-mappable?