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.