-->
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.  [ 1 post ] 
Author Message
 Post subject: table mapped to two classes - both not updating...
PostPosted: Mon Aug 03, 2009 6:50 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 10:51 pm
Posts: 29
Location: sydney australia
Hi all,

I've got an unusual requirement of having a particular class mapped twice. The table stores file attachments along with their meta-data, so in most cases all I need is a collection of the meta-data and not the actual content, but in CRUD operations and when the file content is being retrieved the full object is needed.

To achieve this I've created two mappings, one with everything but the file content (AttachmentShell), and the other with everything (Attachment).
Code:
...<class name="package.Attachment" table="attachment">...

Code:
...<class name="package.AttachmentShell" table="attachment">...


The attachments are foreign keyed to a parent table which I'll call Parent.

I've mapped AttachmentShell and Parent with a bidirectional one-to-many relationship:

Parent.hbm.xml
Code:
...
<set name="attachments" inverse="true" lazy="true" order-by="id" >
      <key column="parentId" not-null="true"/>
      <one-to-many class="package.AttachmentShell"/>
</set>...

AttachmentShell.hbm.xml
Code:
...
<many-to-one name="parent" class="package.Parent" column="parentId" not-null="true"/>...


The problem is that when I perform my CRUDs on Attachment, I can find no way of forcing hibernate to refresh the Parent.attachments collection until the transaction/session is committed/closed and a new one is started. I've tried evicting the Parent, flushing etc.

Advice appreciated.

Paul.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.