-->
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.  [ 3 posts ] 
Author Message
 Post subject: One-to-many that cannot be mapped? Workaround for HHH-286?
PostPosted: Wed Apr 08, 2009 7:33 am 
Newbie

Joined: Wed Apr 08, 2009 6:59 am
Posts: 4
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?


Last edited by japher on Wed Apr 08, 2009 8:21 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 7:40 am 
Newbie

Joined: Wed Apr 08, 2009 6:59 am
Posts: 4
The mapping files are as follows:

Foo.hbm.xml
Code:
...
<composite-id>
    <key-property name="a" column="A"/>
    <key-property name="b" column="B"/>
</composite-id>
<property name="c" column="C"/>
       
<properties name="exportedKey">
    <property name="a" column="A" insert="false" update="false"/>
    <property name="c" column="C" insert="false" update="false"/>
</properties>

<bag name="bars" cascade="none" inverse="true" lazy="false" fetch="join" order-by="Z">
    <key property-ref="exportedKey">
        <column name="X"/>
        <column name="Y" />
    </key>
    <one-to-many class="Bar"/>
</bag>
...


Bar.hbm.xml:
Code:
...
<composite-id>
    <key-property name="x" column="X"/>
    <key-property name="y" column="Y"/>
    <key-property name="z" column="Z"/>
</composite-id>
...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 8:32 am 
Newbie

Joined: Wed Apr 08, 2009 6:59 am
Posts: 4
Looks like there's another forum post from '07 with the exact same problem but no solution (same scenario using property-ref to link using some primary and some non-primary columns):

http://forum.hibernate.org/viewtopic.php?p=2367808&sid=0db4514086c44a239162418c3f2f7f36


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.